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
316ba886
Commit
316ba886
authored
Jun 18, 2015
by
rht
Browse files
Change Process interface into object variable
License: MIT Signed-off-by:
rht
<
rhtbot@gmail.com
>
parent
e2481a24
Changes
4
Hide whitespace changes
Inline
Side-by-side
net/mock/mock_net.go
View file @
316ba886
...
...
@@ -33,6 +33,7 @@ type mocknet struct {
linkDefaults
LinkOptions
proc
goprocess
.
Process
// for Context closing
ctx
context
.
Context
sync
.
RWMutex
}
...
...
@@ -42,6 +43,7 @@ func New(ctx context.Context) Mocknet {
hosts
:
map
[
peer
.
ID
]
*
bhost
.
BasicHost
{},
links
:
map
[
peer
.
ID
]
map
[
peer
.
ID
]
map
[
*
link
]
struct
{}{},
proc
:
goprocessctx
.
WithContext
(
ctx
),
ctx
:
ctx
,
}
}
...
...
@@ -62,7 +64,7 @@ func (mn *mocknet) GenPeer() (host.Host, error) {
}
func
(
mn
*
mocknet
)
AddPeer
(
k
ic
.
PrivKey
,
a
ma
.
Multiaddr
)
(
host
.
Host
,
error
)
{
n
,
err
:=
newPeernet
(
mn
.
c
g
.
Context
()
,
mn
,
k
,
a
)
n
,
err
:=
newPeernet
(
mn
.
c
tx
,
mn
,
k
,
a
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -70,7 +72,7 @@ func (mn *mocknet) AddPeer(k ic.PrivKey, a ma.Multiaddr) (host.Host, error) {
h
:=
bhost
.
New
(
n
)
log
.
Debugf
(
"mocknet added listen addr for peer: %s -- %s"
,
n
.
LocalPeer
(),
a
)
mn
.
c
g
.
AddChild
(
n
.
c
g
)
mn
.
pro
c
.
AddChild
(
n
.
pro
c
)
mn
.
Lock
()
mn
.
nets
[
n
.
peer
]
=
n
...
...
@@ -298,11 +300,11 @@ func (mn *mocknet) ConnectAll() error {
}
func
(
mn
*
mocknet
)
ConnectPeers
(
a
,
b
peer
.
ID
)
(
inet
.
Conn
,
error
)
{
return
mn
.
Net
(
a
)
.
DialPeer
(
mn
.
c
g
.
Context
()
,
b
)
return
mn
.
Net
(
a
)
.
DialPeer
(
mn
.
c
tx
,
b
)
}
func
(
mn
*
mocknet
)
ConnectNets
(
a
,
b
inet
.
Network
)
(
inet
.
Conn
,
error
)
{
return
a
.
DialPeer
(
mn
.
c
g
.
Context
()
,
b
.
LocalPeer
())
return
a
.
DialPeer
(
mn
.
c
tx
,
b
.
LocalPeer
())
}
func
(
mn
*
mocknet
)
DisconnectPeers
(
p1
,
p2
peer
.
ID
)
error
{
...
...
net/mock/mock_peernet.go
View file @
316ba886
...
...
@@ -66,7 +66,7 @@ func newPeernet(ctx context.Context, m *mocknet, k ic.PrivKey,
notifs
:
make
(
map
[
inet
.
Notifiee
]
struct
{}),
}
n
.
c
g
.
SetTeardown
(
n
.
teardown
)
n
.
pro
c
.
SetTeardown
(
n
.
teardown
)
return
n
,
nil
}
...
...
@@ -94,7 +94,7 @@ func (pn *peernet) allConns() []*conn {
// Close calls the ContextCloser func
func
(
pn
*
peernet
)
Close
()
error
{
return
pn
.
c
g
.
Close
()
return
pn
.
pro
c
.
Close
()
}
func
(
pn
*
peernet
)
Peerstore
()
peer
.
Peerstore
{
...
...
net/swarm/swarm.go
View file @
316ba886
...
...
@@ -65,6 +65,7 @@ type Swarm struct {
Filters
*
filter
.
Filters
proc
goprocess
.
Process
ctx
context
.
Context
bwc
metrics
.
Reporter
}
...
...
@@ -82,6 +83,7 @@ func NewSwarm(ctx context.Context, listenAddrs []ma.Multiaddr,
local
:
local
,
peers
:
peers
,
proc
:
goprocessctx
.
WithContext
(
ctx
),
ctx
:
ctx
,
dialT
:
DialTimeout
,
notifs
:
make
(
map
[
inet
.
Notifiee
]
ps
.
Notifiee
),
bwc
:
bwc
,
...
...
@@ -137,6 +139,11 @@ func (s *Swarm) Process() goprocess.Process {
return
s
.
proc
}
// Context returns the context of the swarm
func
(
s
*
Swarm
)
Context
()
context
.
Context
{
return
s
.
ctx
}
// Close stops the Swarm.
func
(
s
*
Swarm
)
Close
()
error
{
return
s
.
proc
.
Close
()
...
...
net/swarm/swarm_listen.go
View file @
316ba886
...
...
@@ -64,7 +64,7 @@ func (s *Swarm) setupListener(maddr ma.Multiaddr) error {
log
.
Warning
(
"Listener not given PrivateKey, so WILL NOT SECURE conns."
)
}
log
.
Debugf
(
"Swarm Listening at %s"
,
maddr
)
list
,
err
:=
conn
.
Listen
(
s
.
cg
.
Context
(),
maddr
,
s
.
local
,
sk
)
list
,
err
:=
conn
.
Listen
(
s
.
Context
(),
maddr
,
s
.
local
,
sk
)
if
err
!=
nil
{
return
err
}
...
...
@@ -112,7 +112,7 @@ func (s *Swarm) setupListener(maddr ma.Multiaddr) error {
return
}
}
}(
s
.
cg
.
Context
(),
sl
)
}(
s
.
Context
(),
sl
)
return
nil
}
...
...
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