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-unixfs
Commits
e872482a
Commit
e872482a
authored
10 years ago
by
Juan Batiz-Benet
Committed by
Brian Tiger Chow
10 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor symbol
parent
2f2808e9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
21 deletions
+21
-21
routing/dht/dht.go
routing/dht/dht.go
+21
-21
No files found.
routing/dht/dht.go
View file @
e872482a
...
...
@@ -280,7 +280,7 @@ func (dht *IpfsDHT) handleGetValue(p *peer.Peer, pmes *Message) (*Message, error
}
// Store a value in this peer local storage
func
(
dht
*
IpfsDHT
)
handlePutValue
(
p
*
peer
.
Peer
,
pmes
*
PBDHT
Message
)
{
func (dht *IpfsDHT) handlePutValue(p *peer.Peer, pmes *Message) {
dht.dslock.Lock()
defer dht.dslock.Unlock()
dskey := ds.NewKey(pmes.GetKey())
...
...
@@ -291,7 +291,7 @@ func (dht *IpfsDHT) handlePutValue(p *peer.Peer, pmes *PBDHTMessage) {
}
}
func
(
dht
*
IpfsDHT
)
handlePing
(
p
*
peer
.
Peer
,
pmes
*
PBDHT
Message
)
{
func (dht *IpfsDHT) handlePing(p *peer.Peer, pmes *Message) {
u.DOut("[%s] Responding to ping from [%s]!\n", dht.self.ID.Pretty(), p.ID.Pretty())
resp := Message{
Type: pmes.GetType(),
...
...
@@ -302,7 +302,7 @@ func (dht *IpfsDHT) handlePing(p *peer.Peer, pmes *PBDHTMessage) {
dht.netChan.Outgoing <- swarm.NewMessage(p, resp.ToProtobuf())
}
func
(
dht
*
IpfsDHT
)
handleFindPeer
(
p
*
peer
.
Peer
,
pmes
*
PBDHT
Message
)
{
func (dht *IpfsDHT) handleFindPeer(p *peer.Peer, pmes *Message) {
resp := Message{
Type: pmes.GetType(),
ID: pmes.GetId(),
...
...
@@ -335,9 +335,9 @@ func (dht *IpfsDHT) handleFindPeer(p *peer.Peer, pmes *PBDHTMessage) {
resp.Success = true
}
func
(
dht
*
IpfsDHT
)
handleGetProviders
(
p
*
peer
.
Peer
,
pmes
*
PBDHT
Message
)
{
func (dht *IpfsDHT) handleGetProviders(p *peer.Peer, pmes *Message) {
resp := Message{
Type
:
PBDHT
Message_GET_PROVIDERS
,
Type: Message_GET_PROVIDERS,
Key: pmes.GetKey(),
ID: pmes.GetId(),
Response: true,
...
...
@@ -378,7 +378,7 @@ type providerInfo struct {
Value *peer.Peer
}
func
(
dht
*
IpfsDHT
)
handleAddProvider
(
p
*
peer
.
Peer
,
pmes
*
PBDHT
Message
)
{
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())
dht.providers.AddProvider(key, p)
...
...
@@ -393,7 +393,7 @@ func (dht *IpfsDHT) Halt() {
}
// NOTE: not yet finished, low priority
func
(
dht
*
IpfsDHT
)
handleDiagnostic
(
p
*
peer
.
Peer
,
pmes
*
PBDHT
Message
)
{
func (dht *IpfsDHT) handleDiagnostic(p *peer.Peer, pmes *Message) {
seq := dht.routingTables[0].NearestPeers(kb.ConvertPeerID(dht.self.ID), 10)
listenChan := dht.listener.Listen(pmes.GetId(), len(seq), time.Second*30)
...
...
@@ -415,7 +415,7 @@ func (dht *IpfsDHT) handleDiagnostic(p *peer.Peer, pmes *PBDHTMessage) {
//Timeout, return what we have
goto out
case reqResp := <-listenChan:
pmesOut
:=
new
(
PBDHT
Message
)
pmesOut := new(Message)
err := proto.Unmarshal(reqResp.Data, pmesOut)
if err != nil {
// It broke? eh, whatever, keep going
...
...
@@ -428,7 +428,7 @@ func (dht *IpfsDHT) handleDiagnostic(p *peer.Peer, pmes *PBDHTMessage) {
out:
resp := Message{
Type
:
PBDHT
Message_DIAGNOSTIC
,
Type: Message_DIAGNOSTIC,
ID: pmes.GetId(),
Value: buf.Bytes(),
Response: true,
...
...
@@ -481,9 +481,9 @@ func (dht *IpfsDHT) getValueOrPeers(p *peer.Peer, key u.Key, timeout time.Durati
}
// getValueSingle simply performs the get value RPC with the given parameters
func
(
dht
*
IpfsDHT
)
getValueSingle
(
p
*
peer
.
Peer
,
key
u
.
Key
,
timeout
time
.
Duration
,
level
int
)
(
*
PBDHT
Message
,
error
)
{
func (dht *IpfsDHT) getValueSingle(p *peer.Peer, key u.Key, timeout time.Duration, level int) (*Message, error) {
pmes := Message{
Type
:
PBDHT
Message_GET_VALUE
,
Type: Message_GET_VALUE,
Key: string(key),
Value: []byte{byte(level)},
ID: swarm.GenerateMessageID(),
...
...
@@ -507,7 +507,7 @@ func (dht *IpfsDHT) getValueSingle(p *peer.Peer, key u.Key, timeout time.Duratio
}
roundtrip := time.Since(t)
resp.Peer.SetLatency(roundtrip)
pmesOut
:=
new
(
PBDHT
Message
)
pmesOut := new(Message)
err := proto.Unmarshal(resp.Data, pmesOut)
if err != nil {
return nil, err
...
...
@@ -521,7 +521,7 @@ func (dht *IpfsDHT) getValueSingle(p *peer.Peer, key u.Key, timeout time.Duratio
// one to get the value from? Or just connect to one at a time until we get a
// successful connection and request the value from it?
func (dht *IpfsDHT) getFromPeerList(key u.Key, timeout time.Duration,
peerlist
[]
*
PBDHT
Message_PBPeer
,
level
int
)
([]
byte
,
error
)
{
peerlist []*Message_PBPeer, level int) ([]byte, error) {
for _, pinfo := range peerlist {
p, _ := dht.Find(peer.ID(pinfo.GetId()))
if p == nil {
...
...
@@ -597,9 +597,9 @@ func (dht *IpfsDHT) Find(id peer.ID) (*peer.Peer, *kb.RoutingTable) {
return nil, nil
}
func
(
dht
*
IpfsDHT
)
findPeerSingle
(
p
*
peer
.
Peer
,
id
peer
.
ID
,
timeout
time
.
Duration
,
level
int
)
(
*
PBDHT
Message
,
error
)
{
func (dht *IpfsDHT) findPeerSingle(p *peer.Peer, id peer.ID, timeout time.Duration, level int) (*Message, error) {
pmes := Message{
Type
:
PBDHT
Message_FIND_NODE
,
Type: Message_FIND_NODE,
Key: string(id),
ID: swarm.GenerateMessageID(),
Value: []byte{byte(level)},
...
...
@@ -617,7 +617,7 @@ func (dht *IpfsDHT) findPeerSingle(p *peer.Peer, id peer.ID, timeout time.Durati
case resp := <-listenChan:
roundtrip := time.Since(t)
resp.Peer.SetLatency(roundtrip)
pmesOut
:=
new
(
PBDHT
Message
)
pmesOut := new(Message)
err := proto.Unmarshal(resp.Data, pmesOut)
if err != nil {
return nil, err
...
...
@@ -633,9 +633,9 @@ func (dht *IpfsDHT) printTables() {
}
}
func
(
dht
*
IpfsDHT
)
findProvidersSingle
(
p
*
peer
.
Peer
,
key
u
.
Key
,
level
int
,
timeout
time
.
Duration
)
(
*
PBDHT
Message
,
error
)
{
func (dht *IpfsDHT) findProvidersSingle(p *peer.Peer, key u.Key, level int, timeout time.Duration) (*Message, error) {
pmes := Message{
Type
:
PBDHT
Message_GET_PROVIDERS
,
Type: Message_GET_PROVIDERS,
Key: string(key),
ID: swarm.GenerateMessageID(),
Value: []byte{byte(level)},
...
...
@@ -652,7 +652,7 @@ func (dht *IpfsDHT) findProvidersSingle(p *peer.Peer, key u.Key, level int, time
return nil, u.ErrTimeout
case resp := <-listenChan:
u.DOut("FindProviders: got response.\n")
pmesOut
:=
new
(
PBDHT
Message
)
pmesOut := new(Message)
err := proto.Unmarshal(resp.Data, pmesOut)
if err != nil {
return nil, err
...
...
@@ -663,7 +663,7 @@ func (dht *IpfsDHT) findProvidersSingle(p *peer.Peer, key u.Key, level int, time
}
// TODO: Could be done async
func
(
dht
*
IpfsDHT
)
addPeerList
(
key
u
.
Key
,
peers
[]
*
PBDHT
Message_PBPeer
)
[]
*
peer
.
Peer
{
func (dht *IpfsDHT) addPeerList(key u.Key, peers []*Message_PBPeer) []*peer.Peer {
var provArr []*peer.Peer
for _, prov := range peers {
// Dont add outselves to the list
...
...
@@ -687,7 +687,7 @@ func (dht *IpfsDHT) addPeerList(key u.Key, peers []*PBDHTMessage_PBPeer) []*peer
return provArr
}
func
(
dht
*
IpfsDHT
)
peerFromInfo
(
pbp
*
PBDHT
Message_PBPeer
)
(
*
peer
.
Peer
,
error
)
{
func (dht *IpfsDHT) peerFromInfo(pbp *Message_PBPeer) (*peer.Peer, error) {
maddr, err := ma.NewMultiaddr(pbp.GetAddr())
if err != nil {
return nil, err
...
...
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