Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
go-libp2p
Commits
d859fb0d
Commit
d859fb0d
authored
Sep 18, 2018
by
Can ZHANG
Browse files
Track more info for observed addresses
parent
2787133b
Changes
2
Hide whitespace changes
Inline
Side-by-side
p2p/protocol/identify/id.go
View file @
d859fb0d
...
...
@@ -393,7 +393,8 @@ func (ids *IDService) consumeObservedAddress(observed []byte, c inet.Conn) {
// ok! we have the observed version of one of our ListenAddresses!
log
.
Debugf
(
"added own observed listen addr: %s --> %s"
,
c
.
LocalMultiaddr
(),
maddr
)
ids
.
observedAddrs
.
Add
(
maddr
,
c
.
RemoteMultiaddr
())
ids
.
observedAddrs
.
Add
(
maddr
,
c
.
LocalMultiaddr
(),
c
.
RemoteMultiaddr
(),
c
.
Stat
()
.
Direction
)
}
func
addrInAddrs
(
a
ma
.
Multiaddr
,
as
[]
ma
.
Multiaddr
)
bool
{
...
...
p2p/protocol/identify/obsaddr.go
View file @
d859fb0d
...
...
@@ -4,6 +4,7 @@ import (
"sync"
"time"
net
"github.com/libp2p/go-libp2p-net"
pstore
"github.com/libp2p/go-libp2p-peerstore"
ma
"github.com/multiformats/go-multiaddr"
)
...
...
@@ -16,10 +17,12 @@ const ActivationThresh = 4
// - have been observed at least once recently (1h), because our position in the
// network, or network port mapppings, may have changed.
type
ObservedAddr
struct
{
Addr
ma
.
Multiaddr
SeenBy
map
[
string
]
time
.
Time
LastSeen
time
.
Time
Activated
bool
Addr
ma
.
Multiaddr
// observed address by peers
InternalAddr
ma
.
Multiaddr
// corresponding internal address
SeenBy
map
[
string
]
time
.
Time
LastSeen
time
.
Time
ConnDirection
net
.
Direction
Activated
bool
}
func
(
oa
*
ObservedAddr
)
TryActivate
(
ttl
time
.
Duration
)
bool
{
...
...
@@ -70,7 +73,9 @@ func (oas *ObservedAddrSet) Addrs() []ma.Multiaddr {
return
addrs
}
func
(
oas
*
ObservedAddrSet
)
Add
(
addr
ma
.
Multiaddr
,
observer
ma
.
Multiaddr
)
{
func
(
oas
*
ObservedAddrSet
)
Add
(
observed
,
local
,
observer
ma
.
Multiaddr
,
direction
net
.
Direction
)
{
oas
.
Lock
()
defer
oas
.
Unlock
()
...
...
@@ -80,14 +85,16 @@ func (oas *ObservedAddrSet) Add(addr ma.Multiaddr, observer ma.Multiaddr) {
oas
.
ttl
=
pstore
.
OwnObservedAddrTTL
}
s
:=
addr
.
String
()
s
:=
observed
.
String
()
oa
,
found
:=
oas
.
addrs
[
s
]
// first time seeing address.
if
!
found
{
oa
=
&
ObservedAddr
{
Addr
:
addr
,
SeenBy
:
make
(
map
[
string
]
time
.
Time
),
Addr
:
observed
,
InternalAddr
:
local
,
SeenBy
:
make
(
map
[
string
]
time
.
Time
),
ConnDirection
:
direction
,
}
oas
.
addrs
[
s
]
=
oa
}
...
...
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