Make Id a variable to points to id (renamed from Id())

This way the Id function can be overruled by clients to have
another implementation for the Id function:

To make it static: dns.Id = func() uint16 { return 1234 }
This commit is contained in:
Miek Gieben 2014-07-30 07:17:13 +01:00
parent fb3a1585ad
commit 1243dcbc89
1 changed files with 7 additions and 2 deletions

9
msg.go
View File

@ -51,6 +51,11 @@ var (
ErrRRset error = &Error{err: "bad rrset"}
)
// Id, by default, returns a 16 bits random number to be used as a
// message id. The random provided should be good enough. This being a
// variable the function can be overridden with another implementation.
var Id func() uint16 = id
// A manually-unpacked version of (id, bits).
// This is in its own struct for easy printing.
type MsgHdr struct {
@ -1782,9 +1787,9 @@ func compressionLenSearchType(c map[string]int, r RR) (int, bool) {
return 0, false
}
// Id return a 16 bits random number to be used as a
// id returns a 16 bits random number to be used as a
// message id. The random provided should be good enough.
func Id() uint16 {
func id() uint16 {
return uint16(rand.Int()) ^ uint16(time.Now().Nanosecond())
}