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
f5d1d357
Commit
f5d1d357
authored
Sep 16, 2014
by
Juan Batiz-Benet
Committed by
Brian Tiger Chow
Sep 22, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
comment out diagnostic
it'll have to change lots since the listener is gone
parent
7c8c19c5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
40 deletions
+44
-40
dht.go
dht.go
+44
-40
No files found.
dht.go
View file @
f5d1d357
package
dht
import
(
"bytes"
"crypto/rand"
"errors"
"fmt"
...
...
@@ -341,62 +340,67 @@ type providerInfo struct {
func
(
dht
*
IpfsDHT
)
handleAddProvider
(
p
*
peer
.
Peer
,
pmes
*
Message
)
{
key
:=
u
.
Key
(
pmes
.
GetKey
())
u
.
DOut
(
"[%s] Adding [%s] as a provider for '%s'
\n
"
,
dht
.
self
.
ID
.
Pretty
(),
p
.
ID
.
Pretty
(),
peer
.
ID
(
key
)
.
Pretty
())
u
.
DOut
(
"[%s] Adding [%s] as a provider for '%s'
\n
"
,
dht
.
self
.
ID
.
Pretty
(),
p
.
ID
.
Pretty
(),
peer
.
ID
(
key
)
.
Pretty
())
dht
.
providers
.
AddProvider
(
key
,
p
)
}
// Halt stops all communications from this peer and shut down
// TODO -- remove this in favor of context
func
(
dht
*
IpfsDHT
)
Halt
()
{
dht
.
shutdown
<-
struct
{}{}
dht
.
network
.
Close
()
dht
.
providers
.
Halt
()
dht
.
listener
.
Halt
()
}
// NOTE: not yet finished, low priority
func
(
dht
*
IpfsDHT
)
handleDiagnostic
(
p
*
peer
.
Peer
,
pmes
*
Message
)
{
func
(
dht
*
IpfsDHT
)
handleDiagnostic
(
p
*
peer
.
Peer
,
pmes
*
Message
)
(
*
Message
,
error
)
{
seq
:=
dht
.
routingTables
[
0
]
.
NearestPeers
(
kb
.
ConvertPeerID
(
dht
.
self
.
ID
),
10
)
listenChan
:=
dht
.
listener
.
Listen
(
pmes
.
GetId
(),
len
(
seq
),
time
.
Second
*
30
)
for
_
,
ps
:=
range
seq
{
mes
:=
swarm
.
NewMessage
(
ps
,
pmes
)
dht
.
netChan
.
Outgoing
<-
mes
}
buf
:=
new
(
bytes
.
Buffer
)
di
:=
dht
.
getDiagInfo
()
buf
.
Write
(
di
.
Marshal
())
// NOTE: this shouldnt be a hardcoded value
after
:=
time
.
After
(
time
.
Second
*
20
)
count
:=
len
(
seq
)
for
count
>
0
{
select
{
case
<-
after
:
//Timeout, return what we have
goto
out
case
reqResp
:=
<-
listenChan
:
pmesOut
:=
new
(
Message
)
err
:=
proto
.
Unmarshal
(
reqResp
.
Data
,
pmesOut
)
if
err
!=
nil
{
// It broke? eh, whatever, keep going
continue
}
buf
.
Write
(
reqResp
.
Data
)
count
--
mes
,
err
:=
msg
.
FromObject
(
ps
,
pmes
)
if
err
!=
nil
{
u
.
PErr
(
"handleDiagnostics error creating message: %v
\n
"
,
err
)
continue
}
// dht.sender.SendRequest(context.TODO(), mes)
}
return
nil
,
errors
.
New
(
"not yet ported back"
)
out
:
resp
:=
Message
{
Type
:
Message_DIAGNOSTIC
,
ID
:
pmes
.
GetId
(),
Value
:
buf
.
Bytes
(),
Response
:
true
,
}
mes
:=
swarm
.
NewMessage
(
p
,
resp
.
ToProtobuf
())
dht
.
netChan
.
Outgoing
<-
mes
// buf := new(bytes.Buffer)
// di := dht.getDiagInfo()
// buf.Write(di.Marshal())
//
// // NOTE: this shouldnt be a hardcoded value
// after := time.After(time.Second * 20)
// count := len(seq)
// for count > 0 {
// select {
// case <-after:
// //Timeout, return what we have
// goto out
// case reqResp := <-listenChan:
// pmesOut := new(Message)
// err := proto.Unmarshal(reqResp.Data, pmesOut)
// if err != nil {
// // It broke? eh, whatever, keep going
// continue
// }
// buf.Write(reqResp.Data)
// count--
// }
// }
//
// out:
// resp := Message{
// Type: Message_DIAGNOSTIC,
// ID: pmes.GetId(),
// Value: buf.Bytes(),
// Response: true,
// }
//
// mes := swarm.NewMessage(p, resp.ToProtobuf())
// dht.netChan.Outgoing <- mes
}
func
(
dht
*
IpfsDHT
)
getValueOrPeers
(
p
*
peer
.
Peer
,
key
u
.
Key
,
timeout
time
.
Duration
,
level
int
)
([]
byte
,
[]
*
peer
.
Peer
,
error
)
{
...
...
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