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
51fd99e3
Commit
51fd99e3
authored
Nov 11, 2015
by
Jeromy
Browse files
extract from 0.4.0
parent
5a0162c7
Changes
125
Hide whitespace changes
Inline
Side-by-side
p2p/crypto/key.go
View file @
51fd99e3
...
@@ -19,11 +19,12 @@ import (
...
@@ -19,11 +19,12 @@ import (
"crypto/sha512"
"crypto/sha512"
"hash"
"hash"
proto
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
u
"github.com/ipfs/go-ipfs/util"
logging
"github.com/ipfs/go-ipfs/vendor/go-log-v1.0.0"
pb
"github.com/ipfs/go-libp2p/p2p/crypto/pb"
pb
"github.com/ipfs/go-libp2p/p2p/crypto/pb"
proto
"github.com/gogo/protobuf/proto"
logging
"QmWRypnfEwrgH4k93KEHN5hng7VjKYkWmzDYRuTZeh2Mgh/go-log"
u
"util"
)
)
var
log
=
logging
.
Logger
(
"crypto"
)
var
log
=
logging
.
Logger
(
"crypto"
)
...
...
p2p/crypto/key_test.go
View file @
51fd99e3
...
@@ -4,7 +4,7 @@ import (
...
@@ -4,7 +4,7 @@ import (
.
"github.com/ipfs/go-libp2p/p2p/crypto"
.
"github.com/ipfs/go-libp2p/p2p/crypto"
"bytes"
"bytes"
tu
"
github.com/ipfs/go-ipfs/
util/testutil"
tu
"util/testutil"
"testing"
"testing"
)
)
...
...
p2p/crypto/pb/crypto.pb.go
View file @
51fd99e3
...
@@ -14,7 +14,7 @@ It has these top-level messages:
...
@@ -14,7 +14,7 @@ It has these top-level messages:
*/
*/
package
crypto_pb
package
crypto_pb
import
proto
"github.com/
ipfs/go-ipfs/Godeps/_workspace/src/github.com/
golang/protobuf/proto"
import
proto
"github.com/golang/protobuf/proto"
import
math
"math"
import
math
"math"
// Reference imports to suppress errors if they are not otherwise used.
// Reference imports to suppress errors if they are not otherwise used.
...
...
p2p/crypto/rsa.go
View file @
51fd99e3
...
@@ -8,7 +8,7 @@ import (
...
@@ -8,7 +8,7 @@ import (
"crypto/x509"
"crypto/x509"
"errors"
"errors"
proto
"github.com/
ipfs/go-ipfs/Godeps/_workspace/src/github.com/
gogo/protobuf/proto"
proto
"github.com/gogo/protobuf/proto"
pb
"github.com/ipfs/go-libp2p/p2p/crypto/pb"
pb
"github.com/ipfs/go-libp2p/p2p/crypto/pb"
)
)
...
...
p2p/crypto/secio/al.go
View file @
51fd99e3
...
@@ -13,7 +13,7 @@ import (
...
@@ -13,7 +13,7 @@ import (
"crypto/sha512"
"crypto/sha512"
"hash"
"hash"
bfish
"
github.com/ipfs/go-ipfs/Godeps/_workspace/src/
golang.org/x/crypto/blowfish"
bfish
"golang.org/x/crypto/blowfish"
ci
"github.com/ipfs/go-libp2p/p2p/crypto"
ci
"github.com/ipfs/go-libp2p/p2p/crypto"
)
)
...
...
p2p/crypto/secio/interface.go
View file @
51fd99e3
...
@@ -6,8 +6,8 @@ import (
...
@@ -6,8 +6,8 @@ import (
ci
"github.com/ipfs/go-libp2p/p2p/crypto"
ci
"github.com/ipfs/go-libp2p/p2p/crypto"
msgio
"github.com/
ipfs/go-ipfs/Godeps/_workspace/src/github.com/
jbenet/go-msgio"
msgio
"github.com/jbenet/go-msgio"
context
"
github.com/ipfs/go-ipfs/Godeps/_workspace/src/
golang.org/x/net/context"
context
"golang.org/x/net/context"
peer
"github.com/ipfs/go-libp2p/p2p/peer"
peer
"github.com/ipfs/go-libp2p/p2p/peer"
)
)
...
...
p2p/crypto/secio/pb/spipe.pb.go
View file @
51fd99e3
...
@@ -14,7 +14,7 @@ It has these top-level messages:
...
@@ -14,7 +14,7 @@ It has these top-level messages:
*/
*/
package
spipe_pb
package
spipe_pb
import
proto
"github.com/
ipfs/go-ipfs/Godeps/_workspace/src/github.com/
gogo/protobuf/proto"
import
proto
"github.com/gogo/protobuf/proto"
import
math
"math"
import
math
"math"
// Reference imports to suppress errors if they are not otherwise used.
// Reference imports to suppress errors if they are not otherwise used.
...
...
p2p/crypto/secio/protocol.go
View file @
51fd99e3
...
@@ -9,13 +9,13 @@ import (
...
@@ -9,13 +9,13 @@ import (
"sync"
"sync"
"time"
"time"
msgio
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-msgio"
msgio
"github.com/jbenet/go-msgio"
context
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
context
"golang.org/x/net/context"
u
"github.com/ipfs/go-ipfs/util"
logging
"github.com/ipfs/go-ipfs/vendor/go-log-v1.0.0"
ci
"github.com/ipfs/go-libp2p/p2p/crypto"
ci
"github.com/ipfs/go-libp2p/p2p/crypto"
pb
"github.com/ipfs/go-libp2p/p2p/crypto/secio/pb"
pb
"github.com/ipfs/go-libp2p/p2p/crypto/secio/pb"
peer
"github.com/ipfs/go-libp2p/p2p/peer"
peer
"github.com/ipfs/go-libp2p/p2p/peer"
u
"util"
logging
"QmWRypnfEwrgH4k93KEHN5hng7VjKYkWmzDYRuTZeh2Mgh/go-log"
)
)
var
log
=
logging
.
Logger
(
"secio"
)
var
log
=
logging
.
Logger
(
"secio"
)
...
...
p2p/crypto/secio/rw.go
View file @
51fd99e3
...
@@ -9,10 +9,10 @@ import (
...
@@ -9,10 +9,10 @@ import (
"crypto/hmac"
"crypto/hmac"
proto
"github.com/
ipfs/go-ipfs/Godeps/_workspace/src/github.com/
gogo/protobuf/proto"
proto
"github.com/gogo/protobuf/proto"
msgio
"github.com/
ipfs/go-ipfs/Godeps/_workspace/src/github.com/
jbenet/go-msgio"
msgio
"github.com/jbenet/go-msgio"
mpool
"github.com/
ipfs/go-ipfs/Godeps/_workspace/src/github.com/
jbenet/go-msgio/mpool"
mpool
"github.com/jbenet/go-msgio/mpool"
context
"
github.com/ipfs/go-ipfs/Godeps/_workspace/src/
golang.org/x/net/context"
context
"golang.org/x/net/context"
)
)
const
MaxMsgSize
=
8
*
1024
*
1024
const
MaxMsgSize
=
8
*
1024
*
1024
...
...
p2p/discovery/mdns.go
View file @
51fd99e3
...
@@ -9,13 +9,13 @@ import (
...
@@ -9,13 +9,13 @@ import (
"sync"
"sync"
"time"
"time"
"github.com/
ipfs/go-ipfs/Godeps/_workspace/src/github.com/
cryptix/mdns"
"github.com/cryptix/mdns"
ma
"github.com/
ipfs/go-ipfs/Godeps/_workspace/src/github.com/
jbenet/go-multiaddr"
ma
"github.com/jbenet/go-multiaddr"
manet
"github.com/
ipfs/go-ipfs/Godeps/_workspace/src/github.com/
jbenet/go-multiaddr-net"
manet
"github.com/jbenet/go-multiaddr-net"
logging
"github.com/ipfs/go-ipfs/vendor/go-log-v1.0.0"
"github.com/ipfs/go-libp2p/p2p/host"
"github.com/ipfs/go-libp2p/p2p/host"
"github.com/ipfs/go-libp2p/p2p/peer"
"github.com/ipfs/go-libp2p/p2p/peer"
logging
"QmWRypnfEwrgH4k93KEHN5hng7VjKYkWmzDYRuTZeh2Mgh/go-log"
)
)
var
log
=
logging
.
Logger
(
"mdns"
)
var
log
=
logging
.
Logger
(
"mdns"
)
...
...
p2p/host/basic/basic_host.go
View file @
51fd99e3
...
@@ -3,21 +3,23 @@ package basichost
...
@@ -3,21 +3,23 @@ package basichost
import
(
import
(
"io"
"io"
ma
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr
"
logging
"QmWRypnfEwrgH4k93KEHN5hng7VjKYkWmzDYRuTZeh2Mgh/go-log
"
goproces
s
"github.com/ipfs/go-
ipfs/Godeps/_workspace/src/github.com/jbenet/goproces
s"
metric
s
"github.com/ipfs/go-
libp2p/p2p/metric
s"
context
"github.com/ipfs/go-
ipfs/Godeps/_workspace/src/golang.org/x/net/context
"
mstream
"github.com/ipfs/go-
libp2p/p2p/metrics/stream
"
logging
"github.com/
ipfs/go-ipfs/vendor/go-log-v1.0.0
"
ma
"github.com/
jbenet/go-multiaddr
"
metric
s
"github.com/
ipfs/go-libp2p/util/metric
s"
goproces
s
"github.com/
jbenet/goproces
s"
mstream
"github.com/ipfs/go-libp2p/util/metrics/stream
"
context
"golang.org/x/net/context
"
inet
"github.com/ipfs/go-libp2p/p2p/net"
inet
"github.com/ipfs/go-libp2p/p2p/net"
peer
"github.com/ipfs/go-libp2p/p2p/peer"
peer
"github.com/ipfs/go-libp2p/p2p/peer"
protocol
"github.com/ipfs/go-libp2p/p2p/protocol"
protocol
"github.com/ipfs/go-libp2p/p2p/protocol"
identify
"github.com/ipfs/go-libp2p/p2p/protocol/identify"
identify
"github.com/ipfs/go-libp2p/p2p/protocol/identify"
relay
"github.com/ipfs/go-libp2p/p2p/protocol/relay"
relay
"github.com/ipfs/go-libp2p/p2p/protocol/relay"
msmux
"github.com/whyrusleeping/go-multistream"
)
)
var
log
=
logging
.
Logger
(
"p2p/host/basic"
)
var
log
=
logging
.
Logger
(
"
github.com/ipfs/go-libp2p/
p2p/host/basic"
)
// Option is a type used to pass in options to the host.
// Option is a type used to pass in options to the host.
type
Option
int
type
Option
int
...
@@ -39,7 +41,7 @@ const (
...
@@ -39,7 +41,7 @@ const (
// * uses a nat service to establish NAT port mappings
// * uses a nat service to establish NAT port mappings
type
BasicHost
struct
{
type
BasicHost
struct
{
network
inet
.
Network
network
inet
.
Network
mux
*
protocol
.
Mux
mux
*
msmux
.
MultistreamMuxer
ids
*
identify
.
IDService
ids
*
identify
.
IDService
relay
*
relay
.
RelayService
relay
*
relay
.
RelayService
natmgr
*
natManager
natmgr
*
natManager
...
@@ -53,7 +55,7 @@ type BasicHost struct {
...
@@ -53,7 +55,7 @@ type BasicHost struct {
func
New
(
net
inet
.
Network
,
opts
...
interface
{})
*
BasicHost
{
func
New
(
net
inet
.
Network
,
opts
...
interface
{})
*
BasicHost
{
h
:=
&
BasicHost
{
h
:=
&
BasicHost
{
network
:
net
,
network
:
net
,
mux
:
protocol
.
NewMux
(),
mux
:
msmux
.
NewMultistreamMuxer
(),
bwc
:
metrics
.
NewBandwidthCounter
(),
bwc
:
metrics
.
NewBandwidthCounter
(),
}
}
...
@@ -67,7 +69,12 @@ func New(net inet.Network, opts ...interface{}) *BasicHost {
...
@@ -67,7 +69,12 @@ func New(net inet.Network, opts ...interface{}) *BasicHost {
// setup host services
// setup host services
h
.
ids
=
identify
.
NewIDService
(
h
)
h
.
ids
=
identify
.
NewIDService
(
h
)
h
.
relay
=
relay
.
NewRelayService
(
h
,
h
.
Mux
()
.
HandleSync
)
muxh
:=
h
.
Mux
()
.
Handle
handle
:=
func
(
s
inet
.
Stream
)
{
muxh
(
s
)
}
h
.
relay
=
relay
.
NewRelayService
(
h
,
handle
)
for
_
,
o
:=
range
opts
{
for
_
,
o
:=
range
opts
{
switch
o
:=
o
.
(
type
)
{
switch
o
:=
o
.
(
type
)
{
...
@@ -95,7 +102,7 @@ func (h *BasicHost) newConnHandler(c inet.Conn) {
...
@@ -95,7 +102,7 @@ func (h *BasicHost) newConnHandler(c inet.Conn) {
// newStreamHandler is the remote-opened stream handler for inet.Network
// newStreamHandler is the remote-opened stream handler for inet.Network
// TODO: this feels a bit wonky
// TODO: this feels a bit wonky
func
(
h
*
BasicHost
)
newStreamHandler
(
s
inet
.
Stream
)
{
func
(
h
*
BasicHost
)
newStreamHandler
(
s
inet
.
Stream
)
{
protoID
,
handle
,
err
:=
h
.
Mux
()
.
ReadHeader
(
s
)
protoID
,
handle
,
err
:=
h
.
Mux
()
.
Negotiate
(
s
)
if
err
!=
nil
{
if
err
!=
nil
{
if
err
==
io
.
EOF
{
if
err
==
io
.
EOF
{
log
.
Debugf
(
"protocol EOF: %s"
,
s
.
Conn
()
.
RemotePeer
())
log
.
Debugf
(
"protocol EOF: %s"
,
s
.
Conn
()
.
RemotePeer
())
...
@@ -105,7 +112,7 @@ func (h *BasicHost) newStreamHandler(s inet.Stream) {
...
@@ -105,7 +112,7 @@ func (h *BasicHost) newStreamHandler(s inet.Stream) {
return
return
}
}
logStream
:=
mstream
.
WrapStream
(
s
,
proto
ID
,
h
.
bwc
)
logStream
:=
mstream
.
WrapStream
(
s
,
proto
col
.
ID
(
protoID
)
,
h
.
bwc
)
go
handle
(
logStream
)
go
handle
(
logStream
)
}
}
...
@@ -126,7 +133,7 @@ func (h *BasicHost) Network() inet.Network {
...
@@ -126,7 +133,7 @@ func (h *BasicHost) Network() inet.Network {
}
}
// Mux returns the Mux multiplexing incoming streams to protocol handlers
// Mux returns the Mux multiplexing incoming streams to protocol handlers
func
(
h
*
BasicHost
)
Mux
()
*
protocol
.
Mux
{
func
(
h
*
BasicHost
)
Mux
()
*
msmux
.
MultistreamMuxer
{
return
h
.
mux
return
h
.
mux
}
}
...
@@ -140,12 +147,15 @@ func (h *BasicHost) IDService() *identify.IDService {
...
@@ -140,12 +147,15 @@ func (h *BasicHost) IDService() *identify.IDService {
// host.Mux().SetHandler(proto, handler)
// host.Mux().SetHandler(proto, handler)
// (Threadsafe)
// (Threadsafe)
func
(
h
*
BasicHost
)
SetStreamHandler
(
pid
protocol
.
ID
,
handler
inet
.
StreamHandler
)
{
func
(
h
*
BasicHost
)
SetStreamHandler
(
pid
protocol
.
ID
,
handler
inet
.
StreamHandler
)
{
h
.
Mux
()
.
SetHandler
(
pid
,
handler
)
h
.
Mux
()
.
AddHandler
(
string
(
pid
),
func
(
rwc
io
.
ReadWriteCloser
)
error
{
handler
(
rwc
.
(
inet
.
Stream
))
return
nil
})
}
}
// RemoveStreamHandler returns ..
// RemoveStreamHandler returns ..
func
(
h
*
BasicHost
)
RemoveStreamHandler
(
pid
protocol
.
ID
)
{
func
(
h
*
BasicHost
)
RemoveStreamHandler
(
pid
protocol
.
ID
)
{
h
.
Mux
()
.
RemoveHandler
(
pid
)
h
.
Mux
()
.
RemoveHandler
(
string
(
pid
)
)
}
}
// NewStream opens a new stream to given peer p, and writes a p2p/protocol
// NewStream opens a new stream to given peer p, and writes a p2p/protocol
...
@@ -160,12 +170,11 @@ func (h *BasicHost) NewStream(pid protocol.ID, p peer.ID) (inet.Stream, error) {
...
@@ -160,12 +170,11 @@ func (h *BasicHost) NewStream(pid protocol.ID, p peer.ID) (inet.Stream, error) {
logStream
:=
mstream
.
WrapStream
(
s
,
pid
,
h
.
bwc
)
logStream
:=
mstream
.
WrapStream
(
s
,
pid
,
h
.
bwc
)
if
err
:=
protocol
.
WriteHeader
(
logStream
,
pid
);
err
!=
nil
{
lzcon
:=
msmux
.
NewMSSelect
(
logStream
,
string
(
pid
))
logStream
.
Close
()
return
&
streamWrapper
{
return
nil
,
err
Stream
:
logStream
,
}
rw
:
lzcon
,
},
nil
return
logStream
,
nil
}
}
// Connect ensures there is a connection between this host and the peer with
// Connect ensures there is a connection between this host and the peer with
...
@@ -244,3 +253,16 @@ func (h *BasicHost) Close() error {
...
@@ -244,3 +253,16 @@ func (h *BasicHost) Close() error {
func
(
h
*
BasicHost
)
GetBandwidthReporter
()
metrics
.
Reporter
{
func
(
h
*
BasicHost
)
GetBandwidthReporter
()
metrics
.
Reporter
{
return
h
.
bwc
return
h
.
bwc
}
}
type
streamWrapper
struct
{
inet
.
Stream
rw
io
.
ReadWriter
}
func
(
s
*
streamWrapper
)
Read
(
b
[]
byte
)
(
int
,
error
)
{
return
s
.
rw
.
Read
(
b
)
}
func
(
s
*
streamWrapper
)
Write
(
b
[]
byte
)
(
int
,
error
)
{
return
s
.
rw
.
Write
(
b
)
}
p2p/host/basic/basic_host_test.go
View file @
51fd99e3
...
@@ -9,7 +9,7 @@ import (
...
@@ -9,7 +9,7 @@ import (
protocol
"github.com/ipfs/go-libp2p/p2p/protocol"
protocol
"github.com/ipfs/go-libp2p/p2p/protocol"
testutil
"github.com/ipfs/go-libp2p/p2p/test/util"
testutil
"github.com/ipfs/go-libp2p/p2p/test/util"
context
"
github.com/ipfs/go-ipfs/Godeps/_workspace/src/
golang.org/x/net/context"
context
"golang.org/x/net/context"
)
)
func
TestHostSimple
(
t
*
testing
.
T
)
{
func
TestHostSimple
(
t
*
testing
.
T
)
{
...
...
p2p/host/basic/natmgr.go
View file @
51fd99e3
...
@@ -3,13 +3,13 @@ package basichost
...
@@ -3,13 +3,13 @@ package basichost
import
(
import
(
"sync"
"sync"
ma
"github.com/
ipfs/go-ipfs/Godeps/_workspace/src/github.com/
jbenet/go-multiaddr"
ma
"github.com/jbenet/go-multiaddr"
goprocess
"github.com/
ipfs/go-ipfs/Godeps/_workspace/src/github.com/
jbenet/goprocess"
goprocess
"github.com/jbenet/goprocess"
context
"
github.com/ipfs/go-ipfs/Godeps/_workspace/src/
golang.org/x/net/context"
context
"golang.org/x/net/context"
inat
"github.com/ipfs/go-libp2p/p2p/nat"
inat
"github.com/ipfs/go-libp2p/p2p/nat"
inet
"github.com/ipfs/go-libp2p/p2p/net"
inet
"github.com/ipfs/go-libp2p/p2p/net"
lgbl
"
github.com/ipfs/go-libp2p/
util/eventlog/loggables"
lgbl
"util/eventlog/loggables"
)
)
// natManager takes care of adding + removing port mappings to the nat.
// natManager takes care of adding + removing port mappings to the nat.
...
...
p2p/host/host.go
View file @
51fd99e3
package
host
package
host
import
(
import
(
ma
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
logging
"QmWRypnfEwrgH4k93KEHN5hng7VjKYkWmzDYRuTZeh2Mgh/go-log"
context
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
metrics
"github.com/ipfs/go-libp2p/p2p/metrics"
logging
"github.com/ipfs/go-ipfs/vendor/go-log-v1.0.0"
inet
"github.com/ipfs/go-libp2p/p2p/net"
inet
"github.com/ipfs/go-libp2p/p2p/net"
peer
"github.com/ipfs/go-libp2p/p2p/peer"
peer
"github.com/ipfs/go-libp2p/p2p/peer"
protocol
"github.com/ipfs/go-libp2p/p2p/protocol"
protocol
"github.com/ipfs/go-libp2p/p2p/protocol"
metrics
"github.com/ipfs/go-libp2p/util/metrics"
ma
"github.com/jbenet/go-multiaddr"
context
"golang.org/x/net/context"
msmux
"github.com/whyrusleeping/go-multistream"
)
)
var
log
=
logging
.
Logger
(
"p2p/host"
)
var
log
=
logging
.
Logger
(
"
github.com/ipfs/go-libp2p/
p2p/host"
)
// Host is an object participating in a p2p network, which
// Host is an object participating in a p2p network, which
// implements protocols or provides services. It handles
// implements protocols or provides services. It handles
...
@@ -31,7 +33,7 @@ type Host interface {
...
@@ -31,7 +33,7 @@ type Host interface {
Network
()
inet
.
Network
Network
()
inet
.
Network
// Mux returns the Mux multiplexing incoming streams to protocol handlers
// Mux returns the Mux multiplexing incoming streams to protocol handlers
Mux
()
*
protocol
.
Mux
Mux
()
*
msmux
.
MultistreamMuxer
// Connect ensures there is a connection between this host and the peer with
// Connect ensures there is a connection between this host and the peer with
// given peer.ID. Connect will absorb the addresses in pi into its internal
// given peer.ID. Connect will absorb the addresses in pi into its internal
...
...
p2p/host/routed/routed.go
View file @
51fd99e3
...
@@ -4,20 +4,21 @@ import (
...
@@ -4,20 +4,21 @@ import (
"fmt"
"fmt"
"time"
"time"
ma
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr
"
logging
"QmWRypnfEwrgH4k93KEHN5hng7VjKYkWmzDYRuTZeh2Mgh/go-log
"
context
"github.com/
ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context
"
ma
"github.com/
jbenet/go-multiaddr
"
logging
"github.com/ipfs/go-ipfs/vendor/go-log-v1.0.0
"
context
"golang.org/x/net/context
"
lgbl
"
github.com/ipfs/go-libp2p/
util/eventlog/loggables"
lgbl
"util/eventlog/loggables"
routing
"github.com/ipfs/go-ipfs/routing"
host
"github.com/ipfs/go-libp2p/p2p/host"
host
"github.com/ipfs/go-libp2p/p2p/host"
metrics
"github.com/ipfs/go-libp2p/p2p/metrics"
inet
"github.com/ipfs/go-libp2p/p2p/net"
inet
"github.com/ipfs/go-libp2p/p2p/net"
peer
"github.com/ipfs/go-libp2p/p2p/peer"
peer
"github.com/ipfs/go-libp2p/p2p/peer"
protocol
"github.com/ipfs/go-libp2p/p2p/protocol"
protocol
"github.com/ipfs/go-libp2p/p2p/protocol"
metrics
"github.com/ipfs/go-libp2p/util/metrics"
msmux
"github.com/whyrusleeping/go-multistream"
)
)
var
log
=
logging
.
Logger
(
"p2p/host/routed"
)
var
log
=
logging
.
Logger
(
"
github.com/ipfs/go-libp2p/
p2p/host/routed"
)
// AddressTTL is the expiry time for our addresses.
// AddressTTL is the expiry time for our addresses.
// We expire them quickly.
// We expire them quickly.
...
@@ -28,10 +29,14 @@ const AddressTTL = time.Second * 10
...
@@ -28,10 +29,14 @@ const AddressTTL = time.Second * 10
// it does not have them.
// it does not have them.
type
RoutedHost
struct
{
type
RoutedHost
struct
{
host
host
.
Host
// embedded other host.
host
host
.
Host
// embedded other host.
route
routing
.
IpfsRouting
route
Routing
}
type
Routing
interface
{
FindPeer
(
context
.
Context
,
peer
.
ID
)
(
peer
.
PeerInfo
,
error
)
}
}
func
Wrap
(
h
host
.
Host
,
r
routing
.
Ipfs
Routing
)
*
RoutedHost
{
func
Wrap
(
h
host
.
Host
,
r
Routing
)
*
RoutedHost
{
return
&
RoutedHost
{
h
,
r
}
return
&
RoutedHost
{
h
,
r
}
}
}
...
@@ -97,7 +102,7 @@ func (rh *RoutedHost) Network() inet.Network {
...
@@ -97,7 +102,7 @@ func (rh *RoutedHost) Network() inet.Network {
return
rh
.
host
.
Network
()
return
rh
.
host
.
Network
()
}
}
func
(
rh
*
RoutedHost
)
Mux
()
*
protocol
.
Mux
{
func
(
rh
*
RoutedHost
)
Mux
()
*
msmux
.
MultistreamMuxer
{
return
rh
.
host
.
Mux
()
return
rh
.
host
.
Mux
()
}
}
...
...
util
/metrics/bw_stats.go
→
p2p
/metrics/bw_stats.go
View file @
51fd99e3
package
metrics
package
metrics
import
(
import
(
gm
"github.com/whyrusleeping/go-metrics"
"sync"
"sync"
gm
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/whyrusleeping/go-metrics"
peer
"github.com/ipfs/go-libp2p/p2p/peer"
peer
"github.com/ipfs/go-libp2p/p2p/peer"
protocol
"github.com/ipfs/go-libp2p/p2p/protocol"
protocol
"github.com/ipfs/go-libp2p/p2p/protocol"
)
)
...
...
util
/metrics/conn/conn.go
→
p2p
/metrics/conn/conn.go
View file @
51fd99e3
package
meterconn
package
meterconn
import
(
import
(
m
an
et
"github.com/ipfs/go-
ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr-net
"
met
rics
"github.com/ipfs/go-
libp2p/p2p/metrics
"
metrics
"github.com/ipfs/go-libp2p/
util/metrics
"
transport
"github.com/ipfs/go-libp2p/
p2p/net/transport
"
)
)
type
MeteredConn
struct
{
type
MeteredConn
struct
{
mesRecv
metrics
.
MeterCallback
mesRecv
metrics
.
MeterCallback
mesSent
metrics
.
MeterCallback
mesSent
metrics
.
MeterCallback
mane
t
.
Conn
transpor
t
.
Conn
}
}
func
WrapConn
(
bwc
metrics
.
Reporter
,
c
manet
.
Conn
)
mane
t
.
Conn
{
func
WrapConn
(
bwc
metrics
.
Reporter
,
c
transport
.
Conn
)
transpor
t
.
Conn
{
return
newMeteredConn
(
c
,
bwc
.
LogRecvMessage
,
bwc
.
LogSentMessage
)
return
newMeteredConn
(
c
,
bwc
.
LogRecvMessage
,
bwc
.
LogSentMessage
)
}
}
func
newMeteredConn
(
base
mane
t
.
Conn
,
rcb
metrics
.
MeterCallback
,
scb
metrics
.
MeterCallback
)
mane
t
.
Conn
{
func
newMeteredConn
(
base
transpor
t
.
Conn
,
rcb
metrics
.
MeterCallback
,
scb
metrics
.
MeterCallback
)
transpor
t
.
Conn
{
return
&
MeteredConn
{
return
&
MeteredConn
{
Conn
:
base
,
Conn
:
base
,
mesRecv
:
rcb
,
mesRecv
:
rcb
,
...
...
util
/metrics/interface.go
→
p2p
/metrics/interface.go
View file @
51fd99e3
File moved
util
/metrics/stream/metered.go
→
p2p
/metrics/stream/metered.go
View file @
51fd99e3
package
meterstream
package
meterstream
import
(
import
(
metrics
"github.com/ipfs/go-libp2p/p2p/metrics"
inet
"github.com/ipfs/go-libp2p/p2p/net"
inet
"github.com/ipfs/go-libp2p/p2p/net"
peer
"github.com/ipfs/go-libp2p/p2p/peer"
peer
"github.com/ipfs/go-libp2p/p2p/peer"
protocol
"github.com/ipfs/go-libp2p/p2p/protocol"
protocol
"github.com/ipfs/go-libp2p/p2p/protocol"
metrics
"github.com/ipfs/go-libp2p/util/metrics"
)
)
type
meteredStream
struct
{
type
meteredStream
struct
{
...
...
util
/metrics/stream/metered_test.go
→
p2p
/metrics/stream/metered_test.go
View file @
51fd99e3
...
@@ -5,7 +5,7 @@ import (
...
@@ -5,7 +5,7 @@ import (
"io/ioutil"
"io/ioutil"
"testing"
"testing"
u
"github.com/
ipfs/go-ipfs/util
"
randbo
"github.com/
dustin/randbo
"
inet
"github.com/ipfs/go-libp2p/p2p/net"
inet
"github.com/ipfs/go-libp2p/p2p/net"
peer
"github.com/ipfs/go-libp2p/p2p/peer"
peer
"github.com/ipfs/go-libp2p/p2p/peer"
protocol
"github.com/ipfs/go-libp2p/p2p/protocol"
protocol
"github.com/ipfs/go-libp2p/p2p/protocol"
...
@@ -43,8 +43,8 @@ func TestCallbacksWork(t *testing.T) {
...
@@ -43,8 +43,8 @@ func TestCallbacksWork(t *testing.T) {
toWrite
:=
int64
(
100000
)
toWrite
:=
int64
(
100000
)
toRead
:=
int64
(
100000
)
toRead
:=
int64
(
100000
)
fake
.
ReadBuf
=
io
.
LimitReader
(
u
.
NewTimeSeededRand
(),
toRead
)
fake
.
ReadBuf
=
io
.
LimitReader
(
randbo
.
New
(),
toRead
)
writeData
:=
io
.
LimitReader
(
u
.
NewTimeSeededRand
(),
toWrite
)
writeData
:=
io
.
LimitReader
(
randbo
.
New
(),
toWrite
)
n
,
err
:=
io
.
Copy
(
ms
,
writeData
)
n
,
err
:=
io
.
Copy
(
ms
,
writeData
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
Prev
1
2
3
4
5
…
7
Next
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