Пример #1
0
func parseFlags() (port *int, firstContact *kademlia.Contact) {
	port = flag.Int("port", 6000, "a int")
	firstID := flag.String("first-id", "", "a hexideicimal node ID")
	firstIP := flag.String("first-ip", "", "the TCP address of an existing node")

	flag.Parse()

	if *firstID == "" || *firstIP == "" {
		firstID = nil
		firstIP = nil
	} else {
		firstContact = &kademlia.Contact{}
		*firstContact = kademlia.NewContact(kademlia.NewNodeID(*firstID), *firstIP)
	}

	return
}
Пример #2
0
		contacts = append(contacts, kademlia.NewContact(id, address))
	}

	if contacts.Len() != expectedLen {
		t.Error(fmt.Sprintf("Contacts length should be %d, got %d", expectedLen, contacts.Len()))
	}
}

var contactsLessTests = []struct {
	contact1          kademlia.Contact
	contact2          kademlia.Contact
	lessThanForwards  bool
	lessThanBackwards bool
}{
	{
		kademlia.NewContact(kademlia.NewNodeID("0000000000000000000000000000000000000000"), ""),
		kademlia.NewContact(kademlia.NewNodeID("0000000000000000000000000000000000000001"), ""),
		true,
		false,
	},
	{
		kademlia.NewContact(kademlia.NewNodeID("000000000000000000000000000000000FFFFFFF"), ""),
		kademlia.NewContact(kademlia.NewNodeID("0000000000000000000000000000000000000000"), ""),
		false,
		true,
	},
	{
		kademlia.NewContact(kademlia.NewNodeID("0000000000000000000000000000000000000000"), ""),
		kademlia.NewContact(kademlia.NewNodeID("0000000000000000000000000000000000000000"), ""),
		false,
		false,