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
0aaec876
Commit
0aaec876
authored
Oct 03, 2016
by
Jeromy Johnson
Committed by
GitHub
Oct 03, 2016
Browse files
Merge pull request #128 from libp2p/feat/extracting
extract protocol and maddr-filter
parents
b47ce3fe
1085a076
Changes
24
Hide whitespace changes
Inline
Side-by-side
p2p/host/basic/basic_host.go
View file @
0aaec876
...
@@ -10,10 +10,10 @@ import (
...
@@ -10,10 +10,10 @@ import (
logging
"github.com/ipfs/go-log"
logging
"github.com/ipfs/go-log"
ma
"github.com/jbenet/go-multiaddr"
ma
"github.com/jbenet/go-multiaddr"
goprocess
"github.com/jbenet/goprocess"
goprocess
"github.com/jbenet/goprocess"
protocol
"github.com/libp2p/go-libp2p-protocol"
metrics
"github.com/libp2p/go-libp2p/p2p/metrics"
metrics
"github.com/libp2p/go-libp2p/p2p/metrics"
mstream
"github.com/libp2p/go-libp2p/p2p/metrics/stream"
mstream
"github.com/libp2p/go-libp2p/p2p/metrics/stream"
inet
"github.com/libp2p/go-libp2p/p2p/net"
inet
"github.com/libp2p/go-libp2p/p2p/net"
protocol
"github.com/libp2p/go-libp2p/p2p/protocol"
identify
"github.com/libp2p/go-libp2p/p2p/protocol/identify"
identify
"github.com/libp2p/go-libp2p/p2p/protocol/identify"
relay
"github.com/libp2p/go-libp2p/p2p/protocol/relay"
relay
"github.com/libp2p/go-libp2p/p2p/protocol/relay"
...
...
p2p/host/basic/basic_host_test.go
View file @
0aaec876
...
@@ -7,9 +7,9 @@ import (
...
@@ -7,9 +7,9 @@ import (
"testing"
"testing"
"time"
"time"
protocol
"github.com/libp2p/go-libp2p-protocol"
host
"github.com/libp2p/go-libp2p/p2p/host"
host
"github.com/libp2p/go-libp2p/p2p/host"
inet
"github.com/libp2p/go-libp2p/p2p/net"
inet
"github.com/libp2p/go-libp2p/p2p/net"
protocol
"github.com/libp2p/go-libp2p/p2p/protocol"
testutil
"github.com/libp2p/go-libp2p/p2p/test/util"
testutil
"github.com/libp2p/go-libp2p/p2p/test/util"
)
)
...
...
p2p/host/host.go
View file @
0aaec876
...
@@ -7,9 +7,9 @@ import (
...
@@ -7,9 +7,9 @@ import (
pstore
"github.com/ipfs/go-libp2p-peerstore"
pstore
"github.com/ipfs/go-libp2p-peerstore"
logging
"github.com/ipfs/go-log"
logging
"github.com/ipfs/go-log"
ma
"github.com/jbenet/go-multiaddr"
ma
"github.com/jbenet/go-multiaddr"
protocol
"github.com/libp2p/go-libp2p-protocol"
metrics
"github.com/libp2p/go-libp2p/p2p/metrics"
metrics
"github.com/libp2p/go-libp2p/p2p/metrics"
inet
"github.com/libp2p/go-libp2p/p2p/net"
inet
"github.com/libp2p/go-libp2p/p2p/net"
protocol
"github.com/libp2p/go-libp2p/p2p/protocol"
msmux
"github.com/whyrusleeping/go-multistream"
msmux
"github.com/whyrusleeping/go-multistream"
)
)
...
...
p2p/host/match.go
View file @
0aaec876
package
host
package
host
import
(
import
(
"github.com/libp2p/go-libp2p
/p2p/
protocol"
"github.com/libp2p/go-libp2p
-
protocol"
"strings"
"strings"
semver
"github.com/coreos/go-semver/semver"
semver
"github.com/coreos/go-semver/semver"
...
...
p2p/host/routed/routed.go
View file @
0aaec876
...
@@ -10,10 +10,10 @@ import (
...
@@ -10,10 +10,10 @@ import (
pstore
"github.com/ipfs/go-libp2p-peerstore"
pstore
"github.com/ipfs/go-libp2p-peerstore"
logging
"github.com/ipfs/go-log"
logging
"github.com/ipfs/go-log"
ma
"github.com/jbenet/go-multiaddr"
ma
"github.com/jbenet/go-multiaddr"
protocol
"github.com/libp2p/go-libp2p-protocol"
host
"github.com/libp2p/go-libp2p/p2p/host"
host
"github.com/libp2p/go-libp2p/p2p/host"
metrics
"github.com/libp2p/go-libp2p/p2p/metrics"
metrics
"github.com/libp2p/go-libp2p/p2p/metrics"
inet
"github.com/libp2p/go-libp2p/p2p/net"
inet
"github.com/libp2p/go-libp2p/p2p/net"
protocol
"github.com/libp2p/go-libp2p/p2p/protocol"
msmux
"github.com/whyrusleeping/go-multistream"
msmux
"github.com/whyrusleeping/go-multistream"
)
)
...
...
p2p/metrics/bw_stats.go
View file @
0aaec876
...
@@ -5,7 +5,7 @@ import (
...
@@ -5,7 +5,7 @@ import (
"sync"
"sync"
peer
"github.com/ipfs/go-libp2p-peer"
peer
"github.com/ipfs/go-libp2p-peer"
protocol
"github.com/libp2p/go-libp2p
/p2p/
protocol"
protocol
"github.com/libp2p/go-libp2p
-
protocol"
)
)
type
Stats
struct
{
type
Stats
struct
{
...
...
p2p/metrics/interface.go
View file @
0aaec876
...
@@ -2,7 +2,7 @@ package metrics
...
@@ -2,7 +2,7 @@ package metrics
import
(
import
(
peer
"github.com/ipfs/go-libp2p-peer"
peer
"github.com/ipfs/go-libp2p-peer"
protocol
"github.com/libp2p/go-libp2p
/p2p/
protocol"
protocol
"github.com/libp2p/go-libp2p
-
protocol"
)
)
type
StreamMeterCallback
func
(
int64
,
protocol
.
ID
,
peer
.
ID
)
type
StreamMeterCallback
func
(
int64
,
protocol
.
ID
,
peer
.
ID
)
...
...
p2p/metrics/stream/metered.go
View file @
0aaec876
...
@@ -2,9 +2,9 @@ package meterstream
...
@@ -2,9 +2,9 @@ package meterstream
import
(
import
(
peer
"github.com/ipfs/go-libp2p-peer"
peer
"github.com/ipfs/go-libp2p-peer"
protocol
"github.com/libp2p/go-libp2p-protocol"
metrics
"github.com/libp2p/go-libp2p/p2p/metrics"
metrics
"github.com/libp2p/go-libp2p/p2p/metrics"
inet
"github.com/libp2p/go-libp2p/p2p/net"
inet
"github.com/libp2p/go-libp2p/p2p/net"
protocol
"github.com/libp2p/go-libp2p/p2p/protocol"
)
)
type
meteredStream
struct
{
type
meteredStream
struct
{
...
...
p2p/metrics/stream/metered_test.go
View file @
0aaec876
...
@@ -7,8 +7,8 @@ import (
...
@@ -7,8 +7,8 @@ import (
randbo
"github.com/dustin/randbo"
randbo
"github.com/dustin/randbo"
peer
"github.com/ipfs/go-libp2p-peer"
peer
"github.com/ipfs/go-libp2p-peer"
protocol
"github.com/libp2p/go-libp2p-protocol"
inet
"github.com/libp2p/go-libp2p/p2p/net"
inet
"github.com/libp2p/go-libp2p/p2p/net"
protocol
"github.com/libp2p/go-libp2p/p2p/protocol"
)
)
type
FakeStream
struct
{
type
FakeStream
struct
{
...
...
p2p/net/conn/interface.go
View file @
0aaec876
...
@@ -9,7 +9,7 @@ import (
...
@@ -9,7 +9,7 @@ import (
peer
"github.com/ipfs/go-libp2p-peer"
peer
"github.com/ipfs/go-libp2p-peer"
ma
"github.com/jbenet/go-multiaddr"
ma
"github.com/jbenet/go-multiaddr"
transport
"github.com/libp2p/go-libp2p-transport"
transport
"github.com/libp2p/go-libp2p-transport"
filter
"github.com/libp2p/go-
libp2p/p2p/net/
filter"
filter
"github.com/libp2p/go-
maddr-
filter"
)
)
type
PeerConn
interface
{
type
PeerConn
interface
{
...
...
p2p/net/conn/listen.go
View file @
0aaec876
...
@@ -15,7 +15,7 @@ import (
...
@@ -15,7 +15,7 @@ import (
"github.com/jbenet/goprocess"
"github.com/jbenet/goprocess"
goprocessctx
"github.com/jbenet/goprocess/context"
goprocessctx
"github.com/jbenet/goprocess/context"
transport
"github.com/libp2p/go-libp2p-transport"
transport
"github.com/libp2p/go-libp2p-transport"
filter
"github.com/libp2p/go-
libp2p/p2p/net/
filter"
filter
"github.com/libp2p/go-
maddr-
filter"
msmux
"github.com/whyrusleeping/go-multistream"
msmux
"github.com/whyrusleeping/go-multistream"
)
)
...
...
p2p/net/filter/filter.go
deleted
100644 → 0
View file @
b47ce3fe
package
filter
import
(
"net"
"sync"
ma
"github.com/jbenet/go-multiaddr"
manet
"github.com/jbenet/go-multiaddr-net"
)
type
Filters
struct
{
mu
sync
.
RWMutex
filters
map
[
string
]
*
net
.
IPNet
}
func
NewFilters
()
*
Filters
{
return
&
Filters
{
filters
:
make
(
map
[
string
]
*
net
.
IPNet
),
}
}
func
(
fs
*
Filters
)
AddDialFilter
(
f
*
net
.
IPNet
)
{
fs
.
mu
.
Lock
()
defer
fs
.
mu
.
Unlock
()
fs
.
filters
[
f
.
String
()]
=
f
}
func
(
f
*
Filters
)
AddrBlocked
(
a
ma
.
Multiaddr
)
bool
{
maddr
:=
ma
.
Split
(
a
)
if
len
(
maddr
)
==
0
{
return
false
}
netaddr
,
err
:=
manet
.
ToNetAddr
(
maddr
[
0
])
if
err
!=
nil
{
// if we cant parse it, its probably not blocked
return
false
}
netip
:=
net
.
ParseIP
(
netaddr
.
String
())
if
netip
==
nil
{
return
false
}
f
.
mu
.
RLock
()
defer
f
.
mu
.
RUnlock
()
for
_
,
ft
:=
range
f
.
filters
{
if
ft
.
Contains
(
netip
)
{
return
true
}
}
return
false
}
func
(
f
*
Filters
)
Filters
()
[]
*
net
.
IPNet
{
var
out
[]
*
net
.
IPNet
f
.
mu
.
RLock
()
defer
f
.
mu
.
RUnlock
()
for
_
,
ff
:=
range
f
.
filters
{
out
=
append
(
out
,
ff
)
}
return
out
}
func
(
f
*
Filters
)
Remove
(
ff
*
net
.
IPNet
)
{
f
.
mu
.
Lock
()
defer
f
.
mu
.
Unlock
()
delete
(
f
.
filters
,
ff
.
String
())
}
p2p/net/filter/filter_test.go
deleted
100644 → 0
View file @
b47ce3fe
package
filter
import
(
"net"
"testing"
ma
"github.com/jbenet/go-multiaddr"
)
func
TestFilter
(
t
*
testing
.
T
)
{
f
:=
NewFilters
()
for
_
,
cidr
:=
range
[]
string
{
"1.2.3.0/24"
,
"4.3.2.1/32"
,
"fd00::/8"
,
"fc00::1/128"
,
}
{
_
,
ipnet
,
_
:=
net
.
ParseCIDR
(
cidr
)
f
.
AddDialFilter
(
ipnet
)
}
for
_
,
blocked
:=
range
[]
string
{
"/ip4/1.2.3.4/tcp/123"
,
"/ip4/4.3.2.1/udp/123"
,
"/ip6/fd00::2/tcp/321"
,
"/ip6/fc00::1/udp/321"
,
}
{
maddr
,
err
:=
ma
.
NewMultiaddr
(
blocked
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
if
!
f
.
AddrBlocked
(
maddr
)
{
t
.
Fatalf
(
"expected %s to be blocked"
,
blocked
)
}
}
for
_
,
notBlocked
:=
range
[]
string
{
"/ip4/1.2.4.1/tcp/123"
,
"/ip4/4.3.2.2/udp/123"
,
"/ip6/fe00::1/tcp/321"
,
"/ip6/fc00::2/udp/321"
,
}
{
maddr
,
err
:=
ma
.
NewMultiaddr
(
notBlocked
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
if
f
.
AddrBlocked
(
maddr
)
{
t
.
Fatalf
(
"expected %s to not be blocked"
,
notBlocked
)
}
}
}
p2p/net/interface.go
View file @
0aaec876
...
@@ -8,8 +8,8 @@ import (
...
@@ -8,8 +8,8 @@ import (
pstore
"github.com/ipfs/go-libp2p-peerstore"
pstore
"github.com/ipfs/go-libp2p-peerstore"
ma
"github.com/jbenet/go-multiaddr"
ma
"github.com/jbenet/go-multiaddr"
"github.com/jbenet/goprocess"
"github.com/jbenet/goprocess"
protocol
"github.com/libp2p/go-libp2p-protocol"
conn
"github.com/libp2p/go-libp2p/p2p/net/conn"
conn
"github.com/libp2p/go-libp2p/p2p/net/conn"
protocol
"github.com/libp2p/go-libp2p/p2p/protocol"
)
)
// MessageSizeMax is a soft (recommended) maximum for network messages.
// MessageSizeMax is a soft (recommended) maximum for network messages.
...
...
p2p/net/mock/mock_stream.go
View file @
0aaec876
...
@@ -6,8 +6,8 @@ import (
...
@@ -6,8 +6,8 @@ import (
"time"
"time"
process
"github.com/jbenet/goprocess"
process
"github.com/jbenet/goprocess"
protocol
"github.com/libp2p/go-libp2p-protocol"
inet
"github.com/libp2p/go-libp2p/p2p/net"
inet
"github.com/libp2p/go-libp2p/p2p/net"
protocol
"github.com/libp2p/go-libp2p/p2p/protocol"
)
)
// stream implements inet.Stream
// stream implements inet.Stream
...
...
p2p/net/mock/mock_test.go
View file @
0aaec876
...
@@ -10,8 +10,8 @@ import (
...
@@ -10,8 +10,8 @@ import (
"time"
"time"
peer
"github.com/ipfs/go-libp2p-peer"
peer
"github.com/ipfs/go-libp2p-peer"
protocol
"github.com/libp2p/go-libp2p-protocol"
inet
"github.com/libp2p/go-libp2p/p2p/net"
inet
"github.com/libp2p/go-libp2p/p2p/net"
protocol
"github.com/libp2p/go-libp2p/p2p/protocol"
testutil
"github.com/libp2p/go-libp2p/testutil"
testutil
"github.com/libp2p/go-libp2p/testutil"
"context"
"context"
...
...
p2p/net/swarm/swarm.go
View file @
0aaec876
...
@@ -15,7 +15,6 @@ import (
...
@@ -15,7 +15,6 @@ import (
mconn
"github.com/libp2p/go-libp2p/p2p/metrics/conn"
mconn
"github.com/libp2p/go-libp2p/p2p/metrics/conn"
inet
"github.com/libp2p/go-libp2p/p2p/net"
inet
"github.com/libp2p/go-libp2p/p2p/net"
conn
"github.com/libp2p/go-libp2p/p2p/net/conn"
conn
"github.com/libp2p/go-libp2p/p2p/net/conn"
filter
"github.com/libp2p/go-libp2p/p2p/net/filter"
addrutil
"github.com/libp2p/go-libp2p/p2p/net/swarm/addr"
addrutil
"github.com/libp2p/go-libp2p/p2p/net/swarm/addr"
ci
"github.com/ipfs/go-libp2p-crypto"
ci
"github.com/ipfs/go-libp2p-crypto"
...
@@ -28,6 +27,7 @@ import (
...
@@ -28,6 +27,7 @@ import (
"github.com/jbenet/goprocess"
"github.com/jbenet/goprocess"
goprocessctx
"github.com/jbenet/goprocess/context"
goprocessctx
"github.com/jbenet/goprocess/context"
transport
"github.com/libp2p/go-libp2p-transport"
transport
"github.com/libp2p/go-libp2p-transport"
filter
"github.com/libp2p/go-maddr-filter"
tcpt
"github.com/libp2p/go-tcp-transport"
tcpt
"github.com/libp2p/go-tcp-transport"
psmss
"github.com/whyrusleeping/go-smux-multistream"
psmss
"github.com/whyrusleeping/go-smux-multistream"
spdy
"github.com/whyrusleeping/go-smux-spdystream"
spdy
"github.com/whyrusleeping/go-smux-spdystream"
...
...
p2p/net/swarm/swarm_stream.go
View file @
0aaec876
package
swarm
package
swarm
import
(
import
(
protocol
"github.com/libp2p/go-libp2p-protocol"
inet
"github.com/libp2p/go-libp2p/p2p/net"
inet
"github.com/libp2p/go-libp2p/p2p/net"
protocol
"github.com/libp2p/go-libp2p/p2p/protocol"
ps
"github.com/jbenet/go-peerstream"
ps
"github.com/jbenet/go-peerstream"
)
)
...
...
p2p/protocol/protocol.go
deleted
100644 → 0
View file @
b47ce3fe
package
protocol
// ID is an identifier used to write protocol headers in streams.
type
ID
string
// These are reserved protocol.IDs.
const
(
TestingID
ID
=
"/p2p/_testing"
)
p2p/protocol/relay/relay.go
View file @
0aaec876
...
@@ -9,9 +9,9 @@ import (
...
@@ -9,9 +9,9 @@ import (
peer
"github.com/ipfs/go-libp2p-peer"
peer
"github.com/ipfs/go-libp2p-peer"
logging
"github.com/ipfs/go-log"
logging
"github.com/ipfs/go-log"
mh
"github.com/jbenet/go-multihash"
mh
"github.com/jbenet/go-multihash"
protocol
"github.com/libp2p/go-libp2p-protocol"
host
"github.com/libp2p/go-libp2p/p2p/host"
host
"github.com/libp2p/go-libp2p/p2p/host"
inet
"github.com/libp2p/go-libp2p/p2p/net"
inet
"github.com/libp2p/go-libp2p/p2p/net"
protocol
"github.com/libp2p/go-libp2p/p2p/protocol"
)
)
var
log
=
logging
.
Logger
(
"github.com/libp2p/go-libp2p/p2p/protocol/relay"
)
var
log
=
logging
.
Logger
(
"github.com/libp2p/go-libp2p/p2p/protocol/relay"
)
...
...
Prev
1
2
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