Documentation ¶
Index ¶
- Constants
- func BitsToKademliaID(bArr []string) [IDLength]byte
- func ContactToByte(contactArr []Contact) []byte
- func ErrorHandler(err error)
- func Eth0IP() (string, error)
- func HashData(data []byte) string
- func SendFindContactMessage(contact *Contact, found chan []Contact, sl *Shortlist, target *Contact)
- func SendFindDataMessage(hash string, contact *Contact, found chan []Contact, value chan string)
- func SendPingMessage(contact *Contact, me *Contact) (data, error)
- func SendPongMessage(r response, me *Contact)
- func SendStoreMessage(contact *Contact, b []byte)
- type Contact
- type ContactCandidates
- func (candidates *ContactCandidates) Append(contacts []Contact)
- func (candidates *ContactCandidates) GetContacts(count int) []Contact
- func (candidates *ContactCandidates) Len() int
- func (candidates *ContactCandidates) Less(i, j int) bool
- func (candidates *ContactCandidates) Sort()
- func (candidates *ContactCandidates) Swap(i, j int)
- type Kademlia
- type KademliaID
- type Network
- func (network *Network) Cli(input io.Reader)
- func (network *Network) CliHelper(input io.Reader)
- func (network *Network) HandleFindDataMsg(msg string, r response)
- func (network *Network) HandleFindNodeMsg(msg data, r response)
- func (network *Network) HandlePingMsg(msg data, r response)
- func (network *Network) HandlePongMsg(msg data)
- func (network *Network) HandleStoreMsg(msg string, resp response)
- func (network *Network) IterativeFindData(hash string)
- func (network *Network) IterativeFindNode(target *Contact) []Contact
- func (network *Network) IterativeStore(data []byte)
- func (network *Network) Listen(contact Contact)
- type RoutingTable
- type Shortlist
Constants ¶
const IDLength = 20
the static number of bytes in a KademliaID
const ID_INDEX = 40
Variables ¶
This section is empty.
Functions ¶
func BitsToKademliaID ¶
func ContactToByte ¶
func SendFindContactMessage ¶
func SendFindDataMessage ¶
func SendPingMessage ¶
func SendPongMessage ¶
func SendPongMessage(r response, me *Contact)
func SendStoreMessage ¶
Types ¶
type Contact ¶
type Contact struct { ID *KademliaID Address string // contains filtered or unexported fields }
Contact definition stores the KademliaID, the ip address and the distance
func ByteToContact ¶
func NewContact ¶
func NewContact(id *KademliaID, address string) Contact
NewContact returns a new instance of a Contact
func (*Contact) CalcDistance ¶
func (contact *Contact) CalcDistance(target *KademliaID)
CalcDistance calculates the distance to the target and fills the contacts distance field
type ContactCandidates ¶
type ContactCandidates struct {
// contains filtered or unexported fields
}
ContactCandidates definition stores an array of Contacts
func (*ContactCandidates) Append ¶
func (candidates *ContactCandidates) Append(contacts []Contact)
Append an array of Contacts to the ContactCandidates
func (*ContactCandidates) GetContacts ¶
func (candidates *ContactCandidates) GetContacts(count int) []Contact
GetContacts returns the first count number of Contacts
func (*ContactCandidates) Len ¶
func (candidates *ContactCandidates) Len() int
Len returns the length of the ContactCandidates
func (*ContactCandidates) Less ¶
func (candidates *ContactCandidates) Less(i, j int) bool
Less returns true if the Contact at index i is smaller than the Contact at index j
func (*ContactCandidates) Sort ¶
func (candidates *ContactCandidates) Sort()
Sort the Contacts in ContactCandidates
func (*ContactCandidates) Swap ¶
func (candidates *ContactCandidates) Swap(i, j int)
Swap the position of the Contacts at i and j WARNING does not check if either i or j is within range
type Kademlia ¶
type Kademlia struct { Rtable *RoutingTable // contains filtered or unexported fields }
func (*Kademlia) LookupContact ¶
func (*Kademlia) LookupData ¶
type KademliaID ¶
type definition of a KademliaID
func NewKademliaID ¶
func NewKademliaID(data string) *KademliaID
NewKademliaID returns a new instance of a KademliaID based on the string input
func NewRandomKademliaID ¶
func NewRandomKademliaID() *KademliaID
NewRandomKademliaID returns a new instance of a random KademliaID, change this to a better version if you like
func (KademliaID) CalcDistance ¶
func (kademliaID KademliaID) CalcDistance(target *KademliaID) *KademliaID
CalcDistance returns a new instance of a KademliaID that is built through a bitwise XOR operation betweeen kademliaID and target
func (KademliaID) Equals ¶
func (kademliaID KademliaID) Equals(otherKademliaID *KademliaID) bool
Equals returns true if kademliaID == otherKademliaID (bitwise)
func (KademliaID) Less ¶
func (kademliaID KademliaID) Less(otherKademliaID *KademliaID) bool
Less returns true if kademliaID < otherKademliaID (bitwise)
func (*KademliaID) String ¶
func (kademliaID *KademliaID) String() string
String returns a simple string representation of a KademliaID
type Network ¶
func InitBootstrap ¶
InitBootstrap inits a new node with no known nodes
func InitJoin ¶
InitJoin joins a network with given IP address 1. Grabs ip from eth0 and generates a new nodeID 2. Inserts some known node by pinging a given bootstrap ip 3. Finds new nodes with IterativeFindNode on nodeID (me) 4. Refreshes all buckets further away than its closest neighbor.
func (*Network) HandleFindDataMsg ¶
func (*Network) HandleFindNodeMsg ¶
func (network *Network) HandleFindNodeMsg(msg data, r response)
func (*Network) HandlePingMsg ¶
func (network *Network) HandlePingMsg(msg data, r response)
handles incoming ping msgs
func (*Network) HandlePongMsg ¶
func (network *Network) HandlePongMsg(msg data)
func (*Network) HandleStoreMsg ¶
func (*Network) IterativeFindData ¶
Helper function to call LookupData()
func (*Network) IterativeFindNode ¶
Helper function to call LookupContact()
func (*Network) IterativeStore ¶
Helper function to call Store()
type RoutingTable ¶
type RoutingTable struct {
// contains filtered or unexported fields
}
RoutingTable definition keeps a refrence contact of me and an array of buckets
func NewRoutingTable ¶
func NewRoutingTable(me Contact) *RoutingTable
NewRoutingTable returns a new instance of a RoutingTable
func (*RoutingTable) AddContact ¶
func (routingTable *RoutingTable) AddContact(contact Contact)
AddContact add a new contact to the correct Bucket
func (*RoutingTable) FindClosestContacts ¶
func (routingTable *RoutingTable) FindClosestContacts(target *KademliaID, count int) []Contact
FindClosestContacts finds the count closest Contacts to the target in the RoutingTable
func (*RoutingTable) GetBucketByID ¶
func (routingTable *RoutingTable) GetBucketByID(id *KademliaID) *bucket
Get k-bucket
func (*RoutingTable) GetBucketIndex ¶
func (routingTable *RoutingTable) GetBucketIndex(id *KademliaID) int
getBucketIndex get the correct Bucket index for the KademliaID