Example #1
0
File: node.go Project: pjjw/god
// Join will fetch the routing ring of the Node at addr, pick a location on an empty spot in the received ring and notify the other Node of our joining.
func (self *Node) Join(addr string) (err error) {
	var newNodes common.Remotes
	if err = common.Switch.Call(addr, "Discord.Nodes", 0, &newNodes); err != nil {
		return
	}
	if bytes.Compare(self.GetPosition(), make([]byte, murmur.Size)) == 0 {
		self.SetPosition(common.NewRingNodes(newNodes).GetSlot())
	}
	self.routeLock.Lock()
	self.ring.SetNodes(newNodes)
	self.routeLock.Unlock()
	var x common.Remote
	if err = common.Switch.Call(addr, "Discord.Notify", self.Remote(), &x); err != nil {
		return
	}
	return
}
func (self *Node) client() *client.Conn {
	return client.NewConnRing(common.NewRingNodes(self.node.Nodes()))
}