Enforce identical member configuration among nodes (fixes #63)

This commit is contained in:
Jakob Borg
2014-02-09 23:13:06 +01:00
parent 14b3791b2b
commit fc6eabea28
4 changed files with 67 additions and 29 deletions

View File

@@ -27,6 +27,10 @@ const (
FlagInvalid = 1 << 13
)
var (
ErrClusterHash = fmt.Errorf("Configuration error: mismatched cluster hash")
)
type FileInfo struct {
Name string
Flags uint32
@@ -64,7 +68,8 @@ type Connection struct {
awaiting map[int]chan asyncResult
nextId int
indexSent map[string][2]int64
options map[string]string
peerOptions map[string]string
myOptions map[string]string
optionsLock sync.Mutex
hasSentIndex bool
@@ -106,6 +111,7 @@ func NewConnection(nodeID string, reader io.Reader, writer io.Writer, receiver M
go c.pingerLoop()
if options != nil {
c.myOptions = options
go func() {
c.Lock()
c.mwriter.writeHeader(header{0, c.nextId, messageTypeOptions})
@@ -348,9 +354,14 @@ loop:
case messageTypeOptions:
c.optionsLock.Lock()
c.options = c.mreader.readOptions()
c.peerOptions = c.mreader.readOptions()
c.optionsLock.Unlock()
if mh, rh := c.myOptions["clusterHash"], c.peerOptions["clusterHash"]; len(mh) > 0 && len(rh) > 0 && mh != rh {
c.close(ErrClusterHash)
break loop
}
default:
c.close(fmt.Errorf("Protocol error: %s: unknown message type %#x", c.ID, hdr.msgType))
break loop
@@ -423,5 +434,5 @@ func (c *Connection) Statistics() Statistics {
func (c *Connection) Option(key string) string {
c.optionsLock.Lock()
defer c.optionsLock.Unlock()
return c.options[key]
return c.peerOptions[key]
}