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
e2481a24
Commit
e2481a24
authored
Jun 17, 2015
by
rht
Browse files
Replace ctxgroup.ContextGroup -> goprocess.Process
License: MIT Signed-off-by:
rht
<
rhtbot@gmail.com
>
parent
8ad672a7
Changes
6
Show whitespace changes
Inline
Side-by-side
net/conn/listen.go
View file @
e2481a24
...
...
@@ -5,11 +5,12 @@ import (
"io"
"net"
ctxgroup
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-ctxgroup"
ma
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
manet
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr-net"
reuseport
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-reuseport"
tec
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-temp-err-catcher"
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/goprocess"
goprocessctx
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/goprocess/context"
context
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
ic
"github.com/ipfs/go-ipfs/p2p/crypto"
...
...
@@ -31,7 +32,7 @@ type listener struct {
wrapper
ConnWrapper
cg
ctxgroup
.
ContextGroup
proc
goprocess
.
Process
}
func
(
l
*
listener
)
teardown
()
error
{
...
...
@@ -41,7 +42,7 @@ func (l *listener) teardown() error {
func
(
l
*
listener
)
Close
()
error
{
log
.
Debugf
(
"listener closing: %s %s"
,
l
.
local
,
l
.
Multiaddr
())
return
l
.
c
g
.
Close
()
return
l
.
pro
c
.
Close
()
}
func
(
l
*
listener
)
String
()
string
{
...
...
@@ -157,9 +158,9 @@ func Listen(ctx context.Context, addr ma.Multiaddr, local peer.ID, sk ic.PrivKey
Listener
:
ml
,
local
:
local
,
privk
:
sk
,
cg
:
ctxgroup
.
WithContext
(
ctx
),
proc
:
goprocessctx
.
WithContext
(
ctx
),
}
l
.
c
g
.
SetTeardown
(
l
.
teardown
)
l
.
pro
c
.
SetTeardown
(
l
.
teardown
)
log
.
Debugf
(
"Conn Listener on %s"
,
l
.
Multiaddr
())
log
.
Event
(
ctx
,
"swarmListen"
,
l
)
...
...
net/interface.go
View file @
e2481a24
...
...
@@ -6,8 +6,8 @@ import (
conn
"github.com/ipfs/go-ipfs/p2p/net/conn"
peer
"github.com/ipfs/go-ipfs/p2p/peer"
ctxgroup
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-ctxgroup"
ma
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/goprocess"
context
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
)
...
...
@@ -80,8 +80,8 @@ type Network interface {
// use the known local interfaces.
InterfaceListenAddresses
()
([]
ma
.
Multiaddr
,
error
)
//
CtxGroup
returns the network's
contextGroup
CtxGroup
()
ctxgroup
.
ContextGroup
//
Process
returns the network's
Process
Process
()
goprocess
.
Process
}
// Dialer represents a service that can dial out to peers
...
...
net/mock/mock_net.go
View file @
e2481a24
...
...
@@ -13,8 +13,9 @@ import (
p2putil
"github.com/ipfs/go-ipfs/p2p/test/util"
testutil
"github.com/ipfs/go-ipfs/util/testutil"
ctxgroup
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-ctxgroup"
ma
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/goprocess"
goprocessctx
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/goprocess/context"
context
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
)
...
...
@@ -31,7 +32,7 @@ type mocknet struct {
linkDefaults
LinkOptions
cg
ctxgroup
.
ContextGroup
// for Context closing
proc
goprocess
.
Process
// for Context closing
sync
.
RWMutex
}
...
...
@@ -40,7 +41,7 @@ func New(ctx context.Context) Mocknet {
nets
:
map
[
peer
.
ID
]
*
peernet
{},
hosts
:
map
[
peer
.
ID
]
*
bhost
.
BasicHost
{},
links
:
map
[
peer
.
ID
]
map
[
peer
.
ID
]
map
[
*
link
]
struct
{}{},
cg
:
ctxgroup
.
WithContext
(
ctx
),
proc
:
goprocessctx
.
WithContext
(
ctx
),
}
}
...
...
net/mock/mock_peernet.go
View file @
e2481a24
...
...
@@ -9,8 +9,9 @@ import (
inet
"github.com/ipfs/go-ipfs/p2p/net"
peer
"github.com/ipfs/go-ipfs/p2p/peer"
ctxgroup
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-ctxgroup"
ma
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/goprocess"
goprocessctx
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/goprocess/context"
context
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
)
...
...
@@ -34,7 +35,7 @@ type peernet struct {
notifmu
sync
.
RWMutex
notifs
map
[
inet
.
Notifiee
]
struct
{}
cg
ctxgroup
.
ContextGroup
proc
goprocess
.
Process
sync
.
RWMutex
}
...
...
@@ -57,7 +58,7 @@ func newPeernet(ctx context.Context, m *mocknet, k ic.PrivKey,
mocknet
:
m
,
peer
:
p
,
ps
:
ps
,
cg
:
ctxgroup
.
WithContext
(
ctx
),
proc
:
goprocessctx
.
WithContext
(
ctx
),
connsByPeer
:
map
[
peer
.
ID
]
map
[
*
conn
]
struct
{}{},
connsByLink
:
map
[
*
link
]
map
[
*
conn
]
struct
{}{},
...
...
@@ -223,9 +224,9 @@ func (pn *peernet) removeConn(c *conn) {
delete
(
cs
,
c
)
}
//
CtxGroup
returns the network's
ContextGroup
func
(
pn
*
peernet
)
CtxGroup
()
ctxgroup
.
ContextGroup
{
return
pn
.
c
g
//
Process
returns the network's
Process
func
(
pn
*
peernet
)
Process
()
goprocess
.
Process
{
return
pn
.
pro
c
}
// LocalPeer the network's LocalPeer
...
...
net/swarm/swarm.go
View file @
e2481a24
...
...
@@ -14,11 +14,12 @@ import (
peer
"github.com/ipfs/go-ipfs/p2p/peer"
eventlog
"github.com/ipfs/go-ipfs/thirdparty/eventlog"
ctxgroup
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-ctxgroup"
ma
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
ps
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-peerstream"
pst
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-peerstream/transport"
psy
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-peerstream/transport/yamux"
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/goprocess"
goprocessctx
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/goprocess/context"
prom
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/prometheus/client_golang/prometheus"
mafilter
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/whyrusleeping/multiaddr-filter"
context
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
...
...
@@ -63,7 +64,7 @@ type Swarm struct {
// filters for addresses that shouldnt be dialed
Filters
*
filter
.
Filters
cg
ctxgroup
.
ContextGroup
proc
goprocess
.
Process
bwc
metrics
.
Reporter
}
...
...
@@ -80,7 +81,7 @@ func NewSwarm(ctx context.Context, listenAddrs []ma.Multiaddr,
swarm
:
ps
.
NewSwarm
(
PSTransport
),
local
:
local
,
peers
:
peers
,
cg
:
ctxgroup
.
WithContext
(
ctx
),
proc
:
goprocessctx
.
WithContext
(
ctx
),
dialT
:
DialTimeout
,
notifs
:
make
(
map
[
inet
.
Notifiee
]
ps
.
Notifiee
),
bwc
:
bwc
,
...
...
@@ -88,7 +89,7 @@ func NewSwarm(ctx context.Context, listenAddrs []ma.Multiaddr,
}
// configure Swarm
s
.
c
g
.
SetTeardown
(
s
.
teardown
)
s
.
pro
c
.
SetTeardown
(
s
.
teardown
)
s
.
SetConnHandler
(
nil
)
// make sure to setup our own conn handler.
// setup swarm metrics
...
...
@@ -111,8 +112,6 @@ func (s *Swarm) AddAddrFilter(f string) error {
s
.
Filters
.
AddDialFilter
(
m
)
return
nil
}
// CtxGroup returns the Context Group of the swarm
func
filterAddrs
(
listenAddrs
[]
ma
.
Multiaddr
)
([]
ma
.
Multiaddr
,
error
)
{
if
len
(
listenAddrs
)
>
0
{
filtered
:=
addrutil
.
FilterUsableAddrs
(
listenAddrs
)
...
...
@@ -124,7 +123,6 @@ func filterAddrs(listenAddrs []ma.Multiaddr) ([]ma.Multiaddr, error) {
return
listenAddrs
,
nil
}
// CtxGroup returns the Context Group of the swarm
func
(
s
*
Swarm
)
Listen
(
addrs
...
ma
.
Multiaddr
)
error
{
addrs
,
err
:=
filterAddrs
(
addrs
)
if
err
!=
nil
{
...
...
@@ -134,14 +132,14 @@ func (s *Swarm) Listen(addrs ...ma.Multiaddr) error {
return
s
.
listen
(
addrs
)
}
//
CtxGroup
returns the
Context Group
of the swarm
func
(
s
*
Swarm
)
CtxGroup
()
ctxgroup
.
ContextGroup
{
return
s
.
c
g
//
Process
returns the
Process
of the swarm
func
(
s
*
Swarm
)
Process
()
goprocess
.
Process
{
return
s
.
pro
c
}
// Close stops the Swarm.
func
(
s
*
Swarm
)
Close
()
error
{
return
s
.
c
g
.
Close
()
return
s
.
pro
c
.
Close
()
}
// StreamSwarm returns the underlying peerstream.Swarm
...
...
net/swarm/swarm_net.go
View file @
e2481a24
...
...
@@ -8,8 +8,8 @@ import (
metrics
"github.com/ipfs/go-ipfs/metrics"
inet
"github.com/ipfs/go-ipfs/p2p/net"
ctxgroup
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-ctxgroup"
ma
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/goprocess"
context
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
)
...
...
@@ -43,9 +43,9 @@ func (n *Network) DialPeer(ctx context.Context, p peer.ID) (inet.Conn, error) {
return
inet
.
Conn
(
sc
),
nil
}
//
CtxGroup
returns the network's
ContextGroup
func
(
n
*
Network
)
CtxGroup
()
ctxgroup
.
ContextGroup
{
return
n
.
c
g
//
Process
returns the network's
Process
func
(
n
*
Network
)
Process
()
goprocess
.
Process
{
return
n
.
pro
c
}
// Swarm returns the network's peerstream.Swarm
...
...
@@ -100,7 +100,7 @@ func (n *Network) close() error {
// Close calls the ContextCloser func
func
(
n
*
Network
)
Close
()
error
{
return
n
.
Swarm
()
.
c
g
.
Close
()
return
n
.
Swarm
()
.
pro
c
.
Close
()
}
// Listen tells the network to start listening on given multiaddrs.
...
...
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