mirror of https://github.com/kubernetes/kops.git
Change vendored weave mesh to use hash keys by default
This means we don't have to use build tags when building, so our code is more go-gettable. Also bazel doesn't support build tags yet, so we need to do something like this for a bazel build (otherwise gossip DNS is broken)
This commit is contained in:
parent
3a598a708a
commit
bdf6cc4e6a
|
@ -1788,6 +1788,6 @@
|
|||
[solve-meta]
|
||||
analyzer-name = "dep"
|
||||
analyzer-version = 1
|
||||
inputs-digest = "c083db22a03ca0fe3ccc11361c91a444e674aa1ec6fb0aba6447b4b4982c0355"
|
||||
inputs-digest = "0201881428ebf85b06c6a6868cbc8f0885841e2395a64631bb9406681da3c197"
|
||||
solver-name = "gps-cdcl"
|
||||
solver-version = 1
|
||||
|
|
5
Makefile
5
Makefile
|
@ -469,10 +469,15 @@ dep-prereqs:
|
|||
.PHONY: dep-ensure
|
||||
dep-ensure: dep-prereqs
|
||||
dep ensure -v
|
||||
# Switch weavemesh to use peer_name_hash - bazel rule-go doesn't support build tags yet
|
||||
rm vendor/github.com/weaveworks/mesh/peer_name_mac.go
|
||||
sed -i -e 's/peer_name_hash/!peer_name_mac/g' vendor/github.com/weaveworks/mesh/peer_name_hash.go
|
||||
# Remove all bazel build files that were vendored and regenerate (we assume they are go-gettable)
|
||||
find vendor/ -name "BUILD" -delete
|
||||
find vendor/ -name "BUILD.bazel" -delete
|
||||
bazel run //:gazelle -- -proto disable
|
||||
|
||||
|
||||
.PHONY: gofmt
|
||||
gofmt:
|
||||
gofmt -w -s channels/
|
||||
|
|
|
@ -11,7 +11,7 @@ go_library(
|
|||
"logger.go",
|
||||
"overlay.go",
|
||||
"peer.go",
|
||||
"peer_name_mac.go",
|
||||
"peer_name_hash.go",
|
||||
"peers.go",
|
||||
"protocol.go",
|
||||
"protocol_crypto.go",
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// +build peer_name_hash
|
||||
// +build !peer_name_mac
|
||||
|
||||
package mesh
|
||||
|
||||
|
|
|
@ -1,110 +0,0 @@
|
|||
// +build peer_name_mac !peer_name_alternative
|
||||
|
||||
package mesh
|
||||
|
||||
// The !peer_name_alternative effectively makes this the default,
|
||||
// i.e. to choose an alternative, run
|
||||
//
|
||||
// go build -tags 'peer_name_alternative peer_name_hash'
|
||||
//
|
||||
// Let peer names be MACs...
|
||||
//
|
||||
// MACs need to be unique across our network, or bad things will
|
||||
// happen anyway. So they make pretty good candidates for peer
|
||||
// names. And doing so is pretty efficient both computationally and
|
||||
// network overhead wise.
|
||||
//
|
||||
// Note that we do not mandate *what* MAC should be used as the peer
|
||||
// name. In particular it doesn't actually have to be the MAC of, say,
|
||||
// the network interface the peer is sniffing on.
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
)
|
||||
|
||||
// PeerName is used as a map key. Since net.HardwareAddr isn't suitable for
|
||||
// that - it's a slice, and slices can't be map keys - we convert that to/from
|
||||
// uint64.
|
||||
type PeerName uint64
|
||||
|
||||
const (
|
||||
// PeerNameFlavour is the type of peer names we use.
|
||||
PeerNameFlavour = "mac"
|
||||
|
||||
// NameSize is the number of bytes in a peer name.
|
||||
NameSize = 6
|
||||
|
||||
// UnknownPeerName is used as a sentinel value.
|
||||
UnknownPeerName = PeerName(0)
|
||||
)
|
||||
|
||||
// PeerNameFromUserInput parses PeerName from a user-provided string.
|
||||
func PeerNameFromUserInput(userInput string) (PeerName, error) {
|
||||
return PeerNameFromString(userInput)
|
||||
}
|
||||
|
||||
// PeerNameFromString parses PeerName from a generic string.
|
||||
func PeerNameFromString(nameStr string) (PeerName, error) {
|
||||
var a, b, c, d, e, f uint64
|
||||
|
||||
match := func(format string, args ...interface{}) bool {
|
||||
a, b, c, d, e, f = 0, 0, 0, 0, 0, 0
|
||||
n, err := fmt.Sscanf(nameStr+"\000", format+"\000", args...)
|
||||
return err == nil && n == len(args)
|
||||
}
|
||||
|
||||
switch {
|
||||
case match("%2x:%2x:%2x:%2x:%2x:%2x", &a, &b, &c, &d, &e, &f):
|
||||
case match("::%2x:%2x:%2x:%2x", &c, &d, &e, &f):
|
||||
case match("%2x::%2x:%2x:%2x", &a, &d, &e, &f):
|
||||
case match("%2x:%2x::%2x:%2x", &a, &b, &e, &f):
|
||||
case match("%2x:%2x:%2x::%2x", &a, &b, &c, &f):
|
||||
case match("%2x:%2x:%2x:%2x::", &a, &b, &c, &d):
|
||||
case match("::%2x:%2x:%2x", &d, &e, &f):
|
||||
case match("%2x::%2x:%2x", &a, &e, &f):
|
||||
case match("%2x:%2x::%2x", &a, &b, &f):
|
||||
case match("%2x:%2x:%2x::", &a, &b, &c):
|
||||
case match("::%2x:%2x", &e, &f):
|
||||
case match("%2x::%2x", &a, &f):
|
||||
case match("%2x:%2x::", &a, &b):
|
||||
case match("::%2x", &f):
|
||||
case match("%2x::", &a):
|
||||
default:
|
||||
return UnknownPeerName, fmt.Errorf("invalid peer name format: %q", nameStr)
|
||||
}
|
||||
|
||||
return PeerName(a<<40 | b<<32 | c<<24 | d<<16 | e<<8 | f), nil
|
||||
}
|
||||
|
||||
// PeerNameFromBin parses PeerName from a byte slice.
|
||||
func PeerNameFromBin(nameByte []byte) PeerName {
|
||||
return PeerName(macint(net.HardwareAddr(nameByte)))
|
||||
}
|
||||
|
||||
// bytes encodes PeerName as a byte slice.
|
||||
func (name PeerName) bytes() []byte {
|
||||
return intmac(uint64(name))
|
||||
}
|
||||
|
||||
// String encodes PeerName as a string.
|
||||
func (name PeerName) String() string {
|
||||
return intmac(uint64(name)).String()
|
||||
}
|
||||
|
||||
func macint(mac net.HardwareAddr) (r uint64) {
|
||||
for _, b := range mac {
|
||||
r <<= 8
|
||||
r |= uint64(b)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func intmac(key uint64) (r net.HardwareAddr) {
|
||||
r = make([]byte, 6)
|
||||
for i := 5; i >= 0; i-- {
|
||||
r[i] = byte(key)
|
||||
key >>= 8
|
||||
}
|
||||
return
|
||||
}
|
Loading…
Reference in New Issue