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
91341560
Commit
91341560
authored
10 years ago
by
Jeromy
Committed by
Juan Batiz-Benet
10 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update logging in multiple packages
parent
eaa11048
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
20 deletions
+20
-20
dht/dht.go
dht/dht.go
+15
-15
dht/routing.go
dht/routing.go
+5
-5
No files found.
dht/dht.go
View file @
91341560
...
...
@@ -77,7 +77,7 @@ func NewDHT(p *peer.Peer, ps peer.Peerstore, net inet.Network, sender inet.Sende
// 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
.
Peer
)
(
*
peer
.
Peer
,
error
)
{
u
.
DOut
(
"Connect to new peer: %s
\n
"
,
npeer
.
ID
.
Pretty
())
log
.
Debug
(
"Connect to new peer: %s
\n
"
,
npeer
.
ID
.
Pretty
())
// TODO(jbenet,whyrusleeping)
//
...
...
@@ -132,7 +132,7 @@ func (dht *IpfsDHT) HandleMessage(ctx context.Context, mes msg.NetMessage) msg.N
dht
.
Update
(
mPeer
)
// Print out diagnostic
u
.
DOut
(
"[peer: %s] Got message type: '%s' [from = %s]
\n
"
,
log
.
Debug
(
"[peer: %s] Got message type: '%s' [from = %s]
\n
"
,
dht
.
self
.
ID
.
Pretty
(),
Message_MessageType_name
[
int32
(
pmes
.
GetType
())],
mPeer
.
ID
.
Pretty
())
...
...
@@ -177,7 +177,7 @@ func (dht *IpfsDHT) sendRequest(ctx context.Context, p *peer.Peer, pmes *Message
start
:=
time
.
Now
()
// Print out diagnostic
u
.
DOut
(
"[peer: %s] Sent message type: '%s' [to = %s]
\n
"
,
log
.
Debug
(
"[peer: %s] Sent message type: '%s' [to = %s]
\n
"
,
dht
.
self
.
ID
.
Pretty
(),
Message_MessageType_name
[
int32
(
pmes
.
GetType
())],
p
.
ID
.
Pretty
())
...
...
@@ -224,7 +224,7 @@ func (dht *IpfsDHT) putProvider(ctx context.Context, p *peer.Peer, key string) e
return
err
}
u
.
DOut
(
"[%s] putProvider: %s for %s
\n
"
,
dht
.
self
.
ID
.
Pretty
(),
p
.
ID
.
Pretty
(),
key
)
log
.
Debug
(
"[%s] putProvider: %s for %s"
,
dht
.
self
.
ID
.
Pretty
(),
p
.
ID
.
Pretty
(),
key
)
if
*
rpmes
.
Key
!=
*
pmes
.
Key
{
return
errors
.
New
(
"provider not added correctly"
)
}
...
...
@@ -240,10 +240,10 @@ func (dht *IpfsDHT) getValueOrPeers(ctx context.Context, p *peer.Peer,
return
nil
,
nil
,
err
}
u
.
DOut
(
"pmes.GetValue() %v
\n
"
,
pmes
.
GetValue
())
log
.
Debug
(
"pmes.GetValue() %v"
,
pmes
.
GetValue
())
if
value
:=
pmes
.
GetValue
();
value
!=
nil
{
// Success! We were given the value
u
.
DOut
(
"getValueOrPeers: got value
\n
"
)
log
.
Debug
(
"getValueOrPeers: got value"
)
return
value
,
nil
,
nil
}
...
...
@@ -253,7 +253,7 @@ func (dht *IpfsDHT) getValueOrPeers(ctx context.Context, p *peer.Peer,
if
err
!=
nil
{
return
nil
,
nil
,
err
}
u
.
DOut
(
"getValueOrPeers: get from providers
\n
"
)
log
.
Debug
(
"getValueOrPeers: get from providers"
)
return
val
,
nil
,
nil
}
...
...
@@ -266,7 +266,7 @@ func (dht *IpfsDHT) getValueOrPeers(ctx context.Context, p *peer.Peer,
addr
,
err
:=
ma
.
NewMultiaddr
(
pb
.
GetAddr
())
if
err
!=
nil
{
u
.
P
Err
(
"%v
\n
"
,
err
.
Error
())
log
.
Err
or
(
"%v"
,
err
.
Error
())
continue
}
...
...
@@ -281,11 +281,11 @@ func (dht *IpfsDHT) getValueOrPeers(ctx context.Context, p *peer.Peer,
}
if
len
(
peers
)
>
0
{
u
.
DOut
(
"getValueOrPeers: peers
\n
"
)
u
.
DOut
(
"getValueOrPeers: peers"
)
return
nil
,
peers
,
nil
}
u
.
DOut
(
"getValueOrPeers: u.ErrNotFound
\n
"
)
log
.
Warning
(
"getValueOrPeers: u.ErrNotFound"
)
return
nil
,
nil
,
u
.
ErrNotFound
}
...
...
@@ -307,13 +307,13 @@ func (dht *IpfsDHT) getFromPeerList(ctx context.Context, key u.Key,
for
_
,
pinfo
:=
range
peerlist
{
p
,
err
:=
dht
.
ensureConnectedToPeer
(
pinfo
)
if
err
!=
nil
{
u
.
DEr
r
(
"getFromPeers error: %s
\n
"
,
err
)
log
.
Erro
r
(
"getFromPeers error: %s"
,
err
)
continue
}
pmes
,
err
:=
dht
.
getValueSingle
(
ctx
,
p
,
key
,
level
)
if
err
!=
nil
{
u
.
DEr
r
(
"getFromPeers error: %s
\n
"
,
err
)
log
.
Erro
r
(
"getFromPeers error: %s
\n
"
,
err
)
continue
}
...
...
@@ -348,7 +348,7 @@ func (dht *IpfsDHT) putLocal(key u.Key, value []byte) error {
// Update signals to all routingTables to Update their last-seen status
// on the given peer.
func
(
dht
*
IpfsDHT
)
Update
(
p
*
peer
.
Peer
)
{
u
.
DOut
(
"updating peer: [%s] latency = %f
\n
"
,
p
.
ID
.
Pretty
(),
p
.
GetLatency
()
.
Seconds
())
log
.
Debug
(
"updating peer: [%s] latency = %f
\n
"
,
p
.
ID
.
Pretty
(),
p
.
GetLatency
()
.
Seconds
())
removedCount
:=
0
for
_
,
route
:=
range
dht
.
routingTables
{
removed
:=
route
.
Update
(
p
)
...
...
@@ -404,7 +404,7 @@ func (dht *IpfsDHT) addProviders(key u.Key, peers []*Message_Peer) []*peer.Peer
continue
}
u
.
DOut
(
"[%s] adding provider: %s for %s"
,
dht
.
self
.
ID
.
Pretty
(),
p
,
key
)
log
.
Debug
(
"[%s] adding provider: %s for %s"
,
dht
.
self
.
ID
.
Pretty
(),
p
,
key
)
// Dont add outselves to the list
if
p
.
ID
.
Equal
(
dht
.
self
.
ID
)
{
...
...
@@ -439,7 +439,7 @@ func (dht *IpfsDHT) betterPeerToQuery(pmes *Message) *peer.Peer {
// == to self? nil
if
closer
.
ID
.
Equal
(
dht
.
self
.
ID
)
{
u
.
DOut
(
"Attempted to return self! this shouldnt happen...
\n
"
)
log
.
Error
(
"Attempted to return self! this shouldnt happen..."
)
return
nil
}
...
...
This diff is collapsed.
Click to expand it.
dht/routing.go
View file @
91341560
...
...
@@ -86,7 +86,7 @@ func (dht *IpfsDHT) GetValue(ctx context.Context, key u.Key) ([]byte, error) {
return
nil
,
err
}
u
.
DOut
(
"[%s]
GetValue %v %v
\n
"
,
dht
.
self
.
ID
.
Pretty
()
,
key
,
result
.
value
)
log
.
Debug
(
"
GetValue %v %v
"
,
key
,
result
.
value
)
if
result
.
value
==
nil
{
return
nil
,
u
.
ErrNotFound
}
...
...
@@ -189,7 +189,7 @@ func (dht *IpfsDHT) addPeerListAsync(k u.Key, peers []*Message_Peer, ps *peerSet
// FindProviders searches for peers who can provide the value for given key.
func
(
dht
*
IpfsDHT
)
FindProviders
(
ctx
context
.
Context
,
key
u
.
Key
)
([]
*
peer
.
Peer
,
error
)
{
// get closest peer
u
.
DOut
(
"Find providers for: '%s'
\n
"
,
key
.
Pretty
())
log
.
Debug
(
"Find providers for: '%s'"
,
key
.
Pretty
())
p
:=
dht
.
routingTables
[
0
]
.
NearestPeer
(
kb
.
ConvertKey
(
key
))
if
p
==
nil
{
return
nil
,
nil
...
...
@@ -333,17 +333,17 @@ func (dht *IpfsDHT) findPeerMultiple(ctx context.Context, id peer.ID) (*peer.Pee
// Ping a peer, log the time it took
func
(
dht
*
IpfsDHT
)
Ping
(
ctx
context
.
Context
,
p
*
peer
.
Peer
)
error
{
// Thoughts: maybe this should accept an ID and do a peer lookup?
u
.
DOut
(
"[%s] ping %s start
\n
"
,
dht
.
self
.
ID
.
Pretty
()
,
p
.
ID
.
Pretty
())
log
.
Info
(
"ping %s start"
,
p
.
ID
.
Pretty
())
pmes
:=
newMessage
(
Message_PING
,
""
,
0
)
_
,
err
:=
dht
.
sendRequest
(
ctx
,
p
,
pmes
)
u
.
DOut
(
"[%s]
ping %s end (err = %s)
\n
"
,
dht
.
self
.
ID
.
Pretty
()
,
p
.
ID
.
Pretty
(),
err
)
log
.
Info
(
"
ping %s end (err = %s)
"
,
p
.
ID
.
Pretty
(),
err
)
return
err
}
func
(
dht
*
IpfsDHT
)
getDiagnostic
(
ctx
context
.
Context
)
([]
*
diagInfo
,
error
)
{
u
.
DOut
(
"Begin Diagnostic"
)
log
.
Info
(
"Begin Diagnostic"
)
peers
:=
dht
.
routingTables
[
0
]
.
NearestPeers
(
kb
.
ConvertPeerID
(
dht
.
self
.
ID
),
10
)
var
out
[]
*
diagInfo
...
...
This diff is collapsed.
Click to expand it.
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