Introduce PeerShortIDs
These are needed to support vxlan encapsulation. In a vxlan packet, the only place we can straightforwardly hold the source and destination peer identifiers used by the weave router is in the 24-bit VNI (vxlan network identifier) field. This gives us 12 bits to indicate a peer. The resulting limit of 4096 peers on a weave network does not seem like a problem in the near future. But it does mean that decentralized allocation makes collisions fairly likely even in weave networks of sizes that are common today. Fortunately, the problem is much more tractable than IPAM because we can detect when collisions occur and take action to resolve them.
This commit is contained in:
1 parent
51317dca70
commit
971511e1c5
9 files changed
+558
-30
No files matched your search
+12
-7
@@ -3,6 +3,7 @@ package router
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/rand"
|
||||
"encoding/binary"
|
||||
"encoding/gob"
|
||||
"fmt"
|
||||
"net"
|
||||
@@ -62,15 +63,19 @@ func Concat(elems ...[]byte) []byte {
|
||||
return res
|
||||
}
|
||||
|
||||
func randUint64() (r uint64) {
|
||||
buf := make([]byte, 8)
|
||||
func randBytes(n int) []byte {
|
||||
buf := make([]byte, n)
|
||||
_, err := rand.Read(buf)
|
||||
checkFatal(err)
|
||||
for _, v := range buf {
|
||||
r <<= 8
|
||||
r |= uint64(v)
|
||||
}
|
||||
return
|
||||
return buf
|
||||
}
|
||||
|
||||
func randUint64() (r uint64) {
|
||||
return binary.LittleEndian.Uint64(randBytes(8))
|
||||
}
|
||||
|
||||
func randUint16() (r uint16) {
|
||||
return binary.LittleEndian.Uint16(randBytes(2))
|
||||
}
|
||||
|
||||
func GobEncode(items ...interface{}) []byte {
|
||||
|
||||
Reference in new issue
Block a user