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
Commits
74d26449
Commit
74d26449
authored
Jul 29, 2014
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
whole project go fmt
parent
550971fb
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
49 additions
and
53 deletions
+49
-53
bitswap/bitswap.go
bitswap/bitswap.go
+11
-9
routing/dht/dht.go
routing/dht/dht.go
+2
-3
routing/dht/routing.go
routing/dht/routing.go
+14
-17
routing/routing.go
routing/routing.go
+17
-19
swarm/swarm.go
swarm/swarm.go
+5
-5
No files found.
bitswap/bitswap.go
View file @
74d26449
package
bitswap
import
(
"time"
mh
"github.com/jbenet/go-multihash"
blocks
"github.com/jbenet/go-ipfs/blocks"
u
"github.com/jbenet/go-ipfs/util"
blocks
"github.com/jbenet/go-ipfs/blocks"
peer
"github.com/jbenet/go-ipfs/peer"
u
"github.com/jbenet/go-ipfs/util"
mh
"github.com/jbenet/go-multihash"
"time"
)
// aliases
type
Ledger
struct
{
Owner
mh
.
Multihash
Partner
mh
.
Multihash
Owner
mh
.
Multihash
Partner
mh
.
Multihash
BytesSent
uint64
BytesRecv
uint64
Timestamp
*
time
.
Time
}
type
BitSwap
struct
{
Ledgers
map
[
u
.
Key
]
*
Ledger
// key is peer.ID
HaveList
map
[
u
.
Key
]
*
blocks
.
Block
// key is multihash
WantList
[]
*
mh
.
Multihash
Ledgers
map
[
u
.
Key
]
*
Ledger
// key is peer.ID
HaveList
map
[
u
.
Key
]
*
blocks
.
Block
// key is multihash
WantList
[]
*
mh
.
Multihash
// todo
}
routing/dht/dht.go
View file @
74d26449
...
...
@@ -7,7 +7,6 @@ import (
// TODO. SEE https://github.com/jbenet/node-ipfs/blob/master/submodules/ipfs-dht/index.js
// IpfsDHT is an implementation of Kademlia with Coral and S/Kademlia modifications.
// It is used to implement the base IpfsRouting module.
type
IpfsDHT
struct
{
...
...
@@ -15,7 +14,7 @@ type IpfsDHT struct {
network
*
swarm
.
Swarm
listeners
map
[
uint64
]
chan
swarm
.
Message
listeners
map
[
uint64
]
chan
swarm
.
Message
listenLock
sync
.
RWMutex
}
...
...
@@ -35,7 +34,7 @@ func (dht *IpfsDHT) handleMessages() {
ch
<-
mes
}
//case closeChan: or something
//case closeChan: or something
}
}
}
...
...
routing/dht/routing.go
View file @
74d26449
package
dht
import
(
"time
"
peer
"github.com/jbenet/go-ipfs/
peer
"
u
"github.com/jbenet/go-ipfs/util"
swarm
"github.com/jbenet/go-ipfs/swarm
"
peer
"github.com/jbenet/go-ipfs/peer
"
swarm
"github.com/jbenet/go-ipfs/
swarm
"
u
"github.com/jbenet/go-ipfs/util"
"time
"
)
// This file implements the Routing interface for the IpfsDHT struct.
// Basic Put/Get
// PutValue adds value corresponding to given Key.
func
(
s
*
IpfsDHT
)
PutValue
(
key
u
.
Key
,
value
[]
byte
)
(
error
)
{
func
(
s
*
IpfsDHT
)
PutValue
(
key
u
.
Key
,
value
[]
byte
)
error
{
var
p
*
peer
.
Peer
p
=
s
.
routes
.
NearestNode
(
key
)
...
...
@@ -48,35 +47,33 @@ func (s *IpfsDHT) GetValue(key u.Key, timeout time.Duration) ([]byte, error) {
// Wait for either the response or a timeout
timeup
:=
time
.
After
(
timeout
)
select
{
case
<-
timeup
:
// TODO: unregister listener
return
nil
,
timeoutError
case
resp
:=
<-
response_chan
:
return
resp
.
Data
,
nil
case
<-
timeup
:
// TODO: unregister listener
return
nil
,
timeoutError
case
resp
:=
<-
response_chan
:
return
resp
.
Data
,
nil
}
// Should never be hit
return
nil
,
nil
}
// Value provider layer of indirection.
// This is what DSHTs (Coral and MainlineDHT) do to store large values in a DHT.
// Announce that this node can provide value for given key
func
(
s
*
IpfsDHT
)
Provide
(
key
u
.
Key
)
(
error
)
{
return
u
.
ErrNotImplemented
func
(
s
*
IpfsDHT
)
Provide
(
key
u
.
Key
)
error
{
return
u
.
ErrNotImplemented
}
// FindProviders searches for peers who can provide the value for given key.
func
(
s
*
IpfsDHT
)
FindProviders
(
key
u
.
Key
,
timeout
time
.
Duration
)
(
*
peer
.
Peer
,
error
)
{
return
nil
,
u
.
ErrNotImplemented
return
nil
,
u
.
ErrNotImplemented
}
// Find specific Peer
// FindPeer searches for a peer with given ID.
func
(
s
*
IpfsDHT
)
FindPeer
(
id
peer
.
ID
,
timeout
time
.
Duration
)
(
*
peer
.
Peer
,
error
)
{
return
nil
,
u
.
ErrNotImplemented
return
nil
,
u
.
ErrNotImplemented
}
routing/routing.go
View file @
74d26449
package
routing
import
(
"time
"
peer
"github.com/jbenet/go-ipfs/
peer
"
u
"github.com/jbenet/go-ipfs/util
"
peer
"github.com/jbenet/go-ipfs/peer
"
u
"github.com/jbenet/go-ipfs/
util
"
"time
"
)
// IpfsRouting is the routing module interface
// It is implemented by things like DHTs, etc.
type
IpfsRouting
interface
{
// Basic Put/Get
// Basic Put/Get
// PutValue adds value corresponding to given Key.
PutValue
(
key
u
.
Key
,
value
[]
byte
)
(
error
)
// PutValue adds value corresponding to given Key.
PutValue
(
key
u
.
Key
,
value
[]
byte
)
error
// GetValue searches for the value corresponding to given Key.
GetValue
(
key
u
.
Key
,
timeout
time
.
Duration
)
([]
byte
,
error
)
// GetValue searches for the value corresponding to given Key.
GetValue
(
key
u
.
Key
,
timeout
time
.
Duration
)
([]
byte
,
error
)
// Value provider layer of indirection.
// This is what DSHTs (Coral and MainlineDHT) do to store large values in a DHT.
//
Value provider layer of indirection.
// This is what DSHTs (Coral and MainlineDHT) do to store large values in a DHT.
//
Announce that this node can provide value for given key
Provide
(
key
u
.
Key
)
error
//
Announce that this node
can provide value for given key
Provide
(
key
u
.
Key
)
(
error
)
//
FindProviders searches for peers who
can provide
the
value for given key
.
Find
Provide
rs
(
key
u
.
Key
,
timeout
time
.
Duration
)
(
*
peer
.
Peer
,
error
)
// FindProviders searches for peers who can provide the value for given key.
FindProviders
(
key
u
.
Key
,
timeout
time
.
Duration
)
(
*
peer
.
Peer
,
error
)
// Find specific Peer
// Find specific Peer
// FindPeer searches for a peer with given ID.
FindPeer
(
id
peer
.
ID
,
timeout
time
.
Duration
)
(
*
peer
.
Peer
,
error
)
// FindPeer searches for a peer with given ID.
FindPeer
(
id
peer
.
ID
,
timeout
time
.
Duration
)
(
*
peer
.
Peer
,
error
)
}
swarm/swarm.go
View file @
74d26449
...
...
@@ -3,10 +3,10 @@ package swarm
import
(
"fmt"
peer
"github.com/jbenet/go-ipfs/peer"
ma
"github.com/jbenet/go-multiaddr"
u
"github.com/jbenet/go-ipfs/util"
"sync
"
ma
"github.com/jbenet/go-multiaddr
"
"net"
"sync"
)
// Message represents a packet of information sent to or received from a
...
...
@@ -46,7 +46,7 @@ type Swarm struct {
conns
ConnMap
connsLock
sync
.
RWMutex
local
*
peer
.
Peer
local
*
peer
.
Peer
}
// NewSwarm constructs a Swarm, with a Chan.
...
...
@@ -62,7 +62,7 @@ func NewSwarm(local *peer.Peer) *Swarm {
// Open listeners for each network the swarm should listen on
func
(
s
*
Swarm
)
Listen
()
{
for
_
,
addr
:=
range
s
.
local
.
Addresses
{
for
_
,
addr
:=
range
s
.
local
.
Addresses
{
err
:=
s
.
connListen
(
addr
)
if
err
!=
nil
{
u
.
PErr
(
"Failed to listen on: %s [%s]"
,
addr
,
err
)
...
...
@@ -85,7 +85,7 @@ func (s *Swarm) connListen(maddr *ma.Multiaddr) error {
// Accept and handle new connections on this listener until it errors
go
func
()
{
for
{
nconn
,
err
:=
list
.
Accept
()
nconn
,
err
:=
list
.
Accept
()
if
err
!=
nil
{
u
.
PErr
(
"Failed to accept connection: %s - %s"
,
netstr
,
addr
)
return
...
...
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