Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DHT PR #25

Merged
merged 30 commits into from
Aug 16, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
61f13ea
begin planning of identification process
Aug 1, 2014
8d98d4b
making connections between nodes get closer to working
whyrusleeping Aug 1, 2014
92fb51d
finish basic communcations between nodes and add a test of the ping o…
Aug 1, 2014
31dc65b
clean up after listeners on shutdown
whyrusleeping Aug 2, 2014
35a4086
rough kbucket implementation, tests and cleanup to follow
whyrusleeping Aug 3, 2014
bade1aa
tests for kbucket and some code cleanup
whyrusleeping Aug 3, 2014
a85ce3f
finish implementation of Put and Get for DHT
whyrusleeping Aug 4, 2014
248e06f
working towards Providers implementation
whyrusleeping Aug 4, 2014
3a76ef0
a little error handling and some work on providers
whyrusleeping Aug 5, 2014
71c7c58
providers interface is coming along nicely
whyrusleeping Aug 6, 2014
dc451fb
implement find peer rpc
whyrusleeping Aug 6, 2014
bd9fc2b
fix bug in routing table lookups
whyrusleeping Aug 6, 2014
41c124a
worked on gathering data for diagnostic messages and some other misc …
whyrusleeping Aug 7, 2014
c22b6aa
fixing some race conditions
whyrusleeping Aug 7, 2014
01ca93b
fixed small bug introduced during race condition frustration
whyrusleeping Aug 7, 2014
24bfbfe
implement timeouts on listeners for the dht and add diagnostic stuff
whyrusleeping Aug 8, 2014
e14fb56
add a unit test for provides functionality
whyrusleeping Aug 8, 2014
ae6285e
address issues from code review (issue #25)
whyrusleeping Aug 9, 2014
1eaeb3b
make tests pass a little more reliably by changing a port to not overlap
whyrusleeping Aug 9, 2014
9f76043
moved routing table code into its own package
whyrusleeping Aug 9, 2014
67ddab1
tiered put/get implemented
whyrusleeping Aug 10, 2014
a438862
more work implementing coral type lookups
whyrusleeping Aug 11, 2014
0a41abd
starting a new testing framework
whyrusleeping Aug 11, 2014
4cb2e1e
add fauxNet to stand in for Swarm in tests to reproduce various netwo…
whyrusleeping Aug 11, 2014
f09dba7
more tests and add in table filtering by peer latency
whyrusleeping Aug 12, 2014
b8a6fbb
modify use of swarm to not make duplicate connections
whyrusleeping Aug 12, 2014
8542380
not quite working yet, but closer
whyrusleeping Aug 13, 2014
60d061c
fix a few infinitely looping RPCs
whyrusleeping Aug 14, 2014
b7a882b
get implementation according to kademlia spec.
whyrusleeping Aug 15, 2014
8a1fdbb
rewrite message response listening framework
whyrusleeping Aug 16, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions identify/identify.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// The identify package handles how peers identify with eachother upon
// connection to the network
package identify

import (
peer "github.com/jbenet/go-ipfs/peer"
u "github.com/jbenet/go-ipfs/util"
)

// Perform initial communication with this peer to share node ID's and
// initiate communication
func Handshake(self, remote *peer.Peer, in, out chan []byte) error {
// TODO: make this more... secure.
out <- self.ID
resp := <-in
remote.ID = peer.ID(resp)
u.DOut("[%s] identify: Got node id: %s", self.ID.Pretty(), remote.ID.Pretty())

return nil
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe the identify pkg could also include a PublicKey func that requests the remote peer's pub key. Handshake could do it if the key's not known locally yet. (RTT lost, prob worth sending along with the id).

3 changes: 3 additions & 0 deletions identify/message.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
message Identify {
required bytes id = 1;
}
30 changes: 28 additions & 2 deletions peer/peer.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package peer

import (
"sync"
"time"

b58 "github.com/jbenet/go-base58"
u "github.com/jbenet/go-ipfs/util"
ma "github.com/jbenet/go-multiaddr"
mh "github.com/jbenet/go-multihash"
Expand All @@ -12,8 +16,12 @@ import (
type ID mh.Multihash

// Utililty function for comparing two peer ID's
func (id *ID) Equal(other *ID) bool {
return bytes.Equal(*id, *other)
func (id ID) Equal(other ID) bool {
return bytes.Equal(id, other)
}

func (id ID) Pretty() string {
return b58.Encode(id)
}

// Map maps Key (string) : *Peer (slices are not comparable).
Expand All @@ -24,6 +32,9 @@ type Map map[u.Key]*Peer
type Peer struct {
ID ID
Addresses []*ma.Multiaddr

latency time.Duration
latenLock sync.RWMutex
}

// Key returns the ID as a Key (string) for maps.
Expand Down Expand Up @@ -52,3 +63,18 @@ func (p *Peer) NetAddress(n string) *ma.Multiaddr {
}
return nil
}

func (p *Peer) GetLatency() (out time.Duration) {
p.latenLock.RLock()
out = p.latency
p.latenLock.RUnlock()
return
}

// TODO: Instead of just keeping a single number,
// keep a running average over the last hour or so
func (p *Peer) SetLatency(laten time.Duration) {
p.latenLock.Lock()
p.latency = laten
p.latenLock.Unlock()
}
49 changes: 49 additions & 0 deletions routing/dht/DHTMessage.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package dht

import (
peer "github.com/jbenet/go-ipfs/peer"
)

// A helper struct to make working with protbuf types easier
type DHTMessage struct {
Type PBDHTMessage_MessageType
Key string
Value []byte
Response bool
Id uint64
Success bool
Peers []*peer.Peer
}

func peerInfo(p *peer.Peer) *PBDHTMessage_PBPeer {
pbp := new(PBDHTMessage_PBPeer)
addr, err := p.Addresses[0].String()
if err != nil {
//Temp: what situations could cause this?
panic(err)
}
pbp.Addr = &addr
pid := string(p.ID)
pbp.Id = &pid
return pbp
}

// TODO: building the protobuf message this way is a little wasteful
// Unused fields wont be omitted, find a better way to do this
func (m *DHTMessage) ToProtobuf() *PBDHTMessage {
pmes := new(PBDHTMessage)
if m.Value != nil {
pmes.Value = m.Value
}

pmes.Type = &m.Type
pmes.Key = &m.Key
pmes.Response = &m.Response
pmes.Id = &m.Id
pmes.Success = &m.Success
for _, p := range m.Peers {
pmes.Peers = append(pmes.Peers, peerInfo(p))
}

return pmes
}
Loading