-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from jbenet/dht
DHT PR
- Loading branch information
Showing
22 changed files
with
2,444 additions
and
215 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
message Identify { | ||
required bytes id = 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.