Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
p2p
go-p2p-kad-dht
Commits
1294aa56
Commit
1294aa56
authored
Jul 31, 2014
by
Jeromy
Committed by
Juan Batiz-Benet
Aug 07, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
making connections between nodes get closer to working
parent
41f5c5c5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
7 deletions
+25
-7
dht.go
dht.go
+25
-7
No files found.
dht.go
View file @
1294aa56
...
...
@@ -55,6 +55,10 @@ func NewDHT(p *peer.Peer) (*IpfsDHT, error) {
return
dht
,
nil
}
func
(
dht
*
IpfsDHT
)
Start
()
{
go
dht
.
handleMessages
()
}
// Connect to a new peer at the given address
func
(
dht
*
IpfsDHT
)
Connect
(
addr
*
ma
.
Multiaddr
)
error
{
peer
:=
new
(
peer
.
Peer
)
...
...
@@ -65,24 +69,26 @@ func (dht *IpfsDHT) Connect(addr *ma.Multiaddr) error {
return
err
}
err
=
identify
.
Handshake
(
dht
.
self
,
con
n
)
err
=
identify
.
Handshake
(
dht
.
self
,
peer
,
conn
.
Incoming
.
MsgChan
,
conn
.
Outgoing
.
MsgCha
n
)
if
err
!=
nil
{
return
err
}
dht
.
network
.
StartConn
(
conn
.
Peer
.
Key
(),
conn
)
dht
.
network
.
StartConn
(
conn
)
// TODO: Add this peer to our routing table
return
nil
}
// Read in all messages from swarm and handle them appropriately
// NOTE: this function is just a quick sketch
func
(
dht
*
IpfsDHT
)
handleMessages
()
{
u
.
DOut
(
"Being message handling routine"
)
for
{
select
{
case
mes
:=
<-
dht
.
network
.
Chan
.
Incoming
:
u
.
DOut
(
"recieved message from swarm."
)
pmes
:=
new
(
DHTMessage
)
err
:=
proto
.
Unmarshal
(
mes
.
Data
,
pmes
)
if
err
!=
nil
{
...
...
@@ -118,6 +124,8 @@ func (dht *IpfsDHT) handleMessages() {
dht
.
handleFindNode
(
mes
.
Peer
,
pmes
)
}
case
err
:=
<-
dht
.
network
.
Chan
.
Errors
:
panic
(
err
)
case
<-
dht
.
shutdown
:
return
}
...
...
@@ -158,10 +166,6 @@ func (dht *IpfsDHT) handlePutValue(p *peer.Peer, pmes *DHTMessage) {
}
}
func
(
dht
*
IpfsDHT
)
handleFindNode
(
p
*
peer
.
Peer
,
pmes
*
DHTMessage
)
{
panic
(
"Not implemented."
)
}
func
(
dht
*
IpfsDHT
)
handlePing
(
p
*
peer
.
Peer
,
pmes
*
DHTMessage
)
{
isResponse
:=
true
resp
:=
new
(
DHTMessage
)
...
...
@@ -172,6 +176,18 @@ func (dht *IpfsDHT) handlePing(p *peer.Peer, pmes *DHTMessage) {
dht
.
network
.
Chan
.
Outgoing
<-
swarm
.
NewMessage
(
p
,
[]
byte
(
resp
.
String
()))
}
func
(
dht
*
IpfsDHT
)
handleFindNode
(
p
*
peer
.
Peer
,
pmes
*
DHTMessage
)
{
panic
(
"Not implemented."
)
}
func
(
dht
*
IpfsDHT
)
handleGetProviders
(
p
*
peer
.
Peer
,
pmes
*
DHTMessage
)
{
panic
(
"Not implemented."
)
}
func
(
dht
*
IpfsDHT
)
handleAddProvider
(
p
*
peer
.
Peer
,
pmes
*
DHTMessage
)
{
panic
(
"Not implemented."
)
}
// Register a handler for a specific message ID, used for getting replies
// to certain messages (i.e. response to a GET_VALUE message)
...
...
@@ -202,6 +218,8 @@ func (dht *IpfsDHT) Halt() {
// Ping a node, log the time it took
func
(
dht
*
IpfsDHT
)
Ping
(
p
*
peer
.
Peer
,
timeout
time
.
Duration
)
{
// Thoughts: maybe this should accept an ID and do a peer lookup?
u
.
DOut
(
"Enter Ping."
)
id
:=
GenerateMessageID
()
mes_type
:=
DHTMessage_PING
pmes
:=
new
(
DHTMessage
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment