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
6400d246
Unverified
Commit
6400d246
authored
Apr 08, 2020
by
Will Scott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test filter caching
parent
8c2c236e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
0 deletions
+43
-0
dht_filters_test.go
dht_filters_test.go
+43
-0
No files found.
dht_filters_test.go
View file @
6400d246
package
dht
import
(
"context"
"net"
"testing"
ic
"github.com/libp2p/go-libp2p-core/crypto"
"github.com/libp2p/go-libp2p-core/network"
"github.com/libp2p/go-libp2p-core/peer"
"github.com/multiformats/go-multiaddr"
ma
"github.com/multiformats/go-multiaddr"
manet
"github.com/multiformats/go-multiaddr-net"
)
func
TestIsRelay
(
t
*
testing
.
T
)
{
...
...
@@ -21,3 +28,39 @@ func TestIsRelay(t *testing.T) {
}
}
type
mockConn
struct
{
local
peer
.
AddrInfo
remote
peer
.
AddrInfo
}
func
(
m
*
mockConn
)
Close
()
error
{
return
nil
}
func
(
m
*
mockConn
)
NewStream
()
(
network
.
Stream
,
error
)
{
return
nil
,
nil
}
func
(
m
*
mockConn
)
GetStreams
()
[]
network
.
Stream
{
return
[]
network
.
Stream
{}
}
func
(
m
*
mockConn
)
Stat
()
network
.
Stat
{
return
network
.
Stat
{
Direction
:
network
.
DirOutbound
}
}
func
(
m
*
mockConn
)
LocalMultiaddr
()
ma
.
Multiaddr
{
return
m
.
local
.
Addrs
[
0
]
}
func
(
m
*
mockConn
)
RemoteMultiaddr
()
ma
.
Multiaddr
{
return
m
.
remote
.
Addrs
[
0
]
}
func
(
m
*
mockConn
)
LocalPeer
()
peer
.
ID
{
return
m
.
local
.
ID
}
func
(
m
*
mockConn
)
LocalPrivateKey
()
ic
.
PrivKey
{
return
nil
}
func
(
m
*
mockConn
)
RemotePeer
()
peer
.
ID
{
return
m
.
remote
.
ID
}
func
(
m
*
mockConn
)
RemotePublicKey
()
ic
.
PubKey
{
return
nil
}
func
TestFilterCaching
(
t
*
testing
.
T
)
{
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
defer
cancel
()
d
:=
setupDHT
(
ctx
,
t
,
true
)
remote
,
_
:=
manet
.
FromIP
(
net
.
IPv4
(
8
,
8
,
8
,
8
))
if
PrivateRoutingTableFilter
(
d
,
[]
network
.
Conn
{
&
mockConn
{
local
:
d
.
Host
()
.
Peerstore
()
.
PeerInfo
(
d
.
Host
()
.
ID
()),
remote
:
peer
.
AddrInfo
{
ID
:
""
,
Addrs
:
[]
ma
.
Multiaddr
{
remote
}},
}})
{
t
.
Fatal
(
"filter should prevent public remote peers."
)
}
r1
:=
getCachedRouter
()
r2
:=
getCachedRouter
()
if
r1
!=
r2
{
t
.
Fatal
(
"router should be returned multiple times."
)
}
}
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