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
dms3
go-dms3-routing
Commits
d1c04c9b
Commit
d1c04c9b
authored
Jul 13, 2015
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
clean up unused dht methods
License: MIT Signed-off-by:
Jeromy
<
jeromyj@gmail.com
>
parent
d25524a4
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
60 deletions
+6
-60
dht/dht.go
dht/dht.go
+0
-57
dht/dht_test.go
dht/dht_test.go
+6
-3
No files found.
dht/dht.go
View file @
d1c04c9b
...
...
@@ -4,7 +4,6 @@ package dht
import
(
"bytes"
"crypto/rand"
"errors"
"fmt"
"sync"
...
...
@@ -33,8 +32,6 @@ var log = eventlog.Logger("dht")
var
ProtocolDHT
protocol
.
ID
=
"/ipfs/dht"
const
doPinging
=
false
// NumBootstrapQueries defines the number of random dht queries to do to
// collect members of the routing table.
const
NumBootstrapQueries
=
5
...
...
@@ -92,11 +89,6 @@ func NewDHT(ctx context.Context, h host.Host, dstore ds.ThreadSafeDatastore) *Ip
dht
.
Validator
=
make
(
record
.
Validator
)
dht
.
Validator
[
"pk"
]
=
record
.
PublicKeyValidator
if
doPinging
{
dht
.
proc
.
Go
(
func
(
p
goprocess
.
Process
)
{
dht
.
PingRoutine
(
time
.
Second
*
10
)
})
}
return
dht
}
...
...
@@ -110,23 +102,6 @@ func (dht *IpfsDHT) log() eventlog.EventLogger {
return
log
// TODO rm
}
// Connect to a new peer at the given address, ping and add to the routing table
func
(
dht
*
IpfsDHT
)
Connect
(
ctx
context
.
Context
,
npeer
peer
.
ID
)
error
{
// TODO: change interface to accept a PeerInfo as well.
if
err
:=
dht
.
host
.
Connect
(
ctx
,
peer
.
PeerInfo
{
ID
:
npeer
});
err
!=
nil
{
return
err
}
// Ping new peer to register in their routing table
// NOTE: this should be done better...
if
_
,
err
:=
dht
.
Ping
(
ctx
,
npeer
);
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to ping newly connected peer: %s"
,
err
)
}
log
.
Event
(
ctx
,
"connect"
,
dht
.
self
,
npeer
)
dht
.
Update
(
ctx
,
npeer
)
return
nil
}
// putValueToPeer stores the given key/value pair at the peer 'p'
func
(
dht
*
IpfsDHT
)
putValueToPeer
(
ctx
context
.
Context
,
p
peer
.
ID
,
key
key
.
Key
,
rec
*
pb
.
Record
)
error
{
...
...
@@ -343,38 +318,6 @@ func (dht *IpfsDHT) betterPeersToQuery(pmes *pb.Message, p peer.ID, count int) [
return
filtered
}
func
(
dht
*
IpfsDHT
)
ensureConnectedToPeer
(
ctx
context
.
Context
,
p
peer
.
ID
)
error
{
if
p
==
dht
.
self
{
return
errors
.
New
(
"attempting to ensure connection to self"
)
}
// dial connection
return
dht
.
host
.
Connect
(
ctx
,
peer
.
PeerInfo
{
ID
:
p
})
}
// PingRoutine periodically pings nearest neighbors.
func
(
dht
*
IpfsDHT
)
PingRoutine
(
t
time
.
Duration
)
{
tick
:=
time
.
Tick
(
t
)
for
{
select
{
case
<-
tick
:
id
:=
make
([]
byte
,
16
)
rand
.
Read
(
id
)
peers
:=
dht
.
routingTable
.
NearestPeers
(
kb
.
ConvertKey
(
key
.
Key
(
id
)),
5
)
for
_
,
p
:=
range
peers
{
ctx
,
cancel
:=
context
.
WithTimeout
(
dht
.
Context
(),
time
.
Second
*
5
)
_
,
err
:=
dht
.
Ping
(
ctx
,
p
)
if
err
!=
nil
{
log
.
Debugf
(
"Ping error: %s"
,
err
)
}
cancel
()
}
case
<-
dht
.
proc
.
Closing
()
:
return
}
}
}
// Context return dht's context
func
(
dht
*
IpfsDHT
)
Context
()
context
.
Context
{
return
dht
.
ctx
...
...
dht/dht_test.go
View file @
d1c04c9b
...
...
@@ -74,7 +74,8 @@ func connect(t *testing.T, ctx context.Context, a, b *IpfsDHT) {
}
a
.
peerstore
.
AddAddrs
(
idB
,
addrB
,
peer
.
TempAddrTTL
)
if
err
:=
a
.
Connect
(
ctx
,
idB
);
err
!=
nil
{
pi
:=
peer
.
PeerInfo
{
ID
:
idB
}
if
err
:=
a
.
host
.
Connect
(
ctx
,
pi
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
}
...
...
@@ -789,12 +790,14 @@ func TestConnectCollision(t *testing.T) {
errs
:=
make
(
chan
error
)
go
func
()
{
dhtA
.
peerstore
.
AddAddr
(
peerB
,
addrB
,
peer
.
TempAddrTTL
)
err
:=
dhtA
.
Connect
(
ctx
,
peerB
)
pi
:=
peer
.
PeerInfo
{
ID
:
peerB
}
err
:=
dhtA
.
host
.
Connect
(
ctx
,
pi
)
errs
<-
err
}()
go
func
()
{
dhtB
.
peerstore
.
AddAddr
(
peerA
,
addrA
,
peer
.
TempAddrTTL
)
err
:=
dhtB
.
Connect
(
ctx
,
peerA
)
pi
:=
peer
.
PeerInfo
{
ID
:
peerA
}
err
:=
dhtB
.
host
.
Connect
(
ctx
,
pi
)
errs
<-
err
}()
...
...
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