func (n *LinkedListNode) Join(new chord.Node) error { newAsLinked, ok := new.(*LinkedListNode) if !ok { return fmt.Errorf("Attempted to join with a non linked-list node") } succ := n.FindSuccessor(new.Identifier()) asLinked := succ.(*LinkedListNode) asLinked.insertBefore(newAsLinked) return nil }
func TestRing(t *testing.T) { first := node.NewLinkedList(chord.ID(10)) r := ring.Ring{Known: first} for _, id := range []chord.ID{chord.ID(1), chord.ID(10), chord.ID(20)} { res, _ := r.Lookup(id) assert.Equal(t, first.Identifier(), res.Identifier()) } second := node.LinkedListNode{ ID: chord.ID(20), } assert.Nil(t, r.Join(&second)) first.Dump() var res chord.Node res, _ = r.Lookup(chord.ID(1)) assert.Equal(t, first.Identifier(), res.Identifier()) res, _ = r.Lookup(chord.ID(12)) assert.Equal(t, second.Identifier(), res.Identifier()) res, _ = r.Lookup(chord.ID(21)) assert.Equal(t, first.Identifier(), res.Identifier()) }
func OwnsID(n chord.Node, id chord.ID) bool { if n.Successor().Identifier() == n.Identifier() { return true } pre := n.Predecessor() if pre.Identifier() > n.Identifier() { return id > pre.Identifier() || id <= n.Identifier() } return id <= n.Identifier() && id > pre.Identifier() }