Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mybee
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
mybee
Commits
3839f3fa
Commit
3839f3fa
authored
Jan 28, 2020
by
Janos Guljas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add p2p Disconnect method
parent
7eb14f1e
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
27 additions
and
14 deletions
+27
-14
peer_test.go
pkg/debugapi/peer_test.go
+8
-6
libp2p.go
pkg/p2p/libp2p/libp2p.go
+9
-0
mock.go
pkg/p2p/mock/mock.go
+9
-8
p2p.go
pkg/p2p/p2p.go
+1
-0
No files found.
pkg/debugapi/peer_test.go
View file @
3839f3fa
...
...
@@ -24,12 +24,14 @@ func TestConnect(t *testing.T) {
testErr
:=
errors
.
New
(
"test error"
)
client
,
cleanup
:=
newTestServer
(
t
,
testServerOptions
{
P2P
:
mock
.
NewService
(
func
(
ctx
context
.
Context
,
addr
ma
.
Multiaddr
)
(
string
,
error
)
{
if
addr
.
String
()
==
errorUnderlay
{
return
""
,
testErr
}
return
overlay
,
nil
}),
P2P
:
&
mock
.
Service
{
ConnectFunc
:
func
(
ctx
context
.
Context
,
addr
ma
.
Multiaddr
)
(
string
,
error
)
{
if
addr
.
String
()
==
errorUnderlay
{
return
""
,
testErr
}
return
overlay
,
nil
},
},
})
defer
cleanup
()
...
...
pkg/p2p/libp2p/libp2p.go
View file @
3839f3fa
...
...
@@ -327,6 +327,15 @@ func (s *Service) Connect(ctx context.Context, addr ma.Multiaddr) (overlay strin
s
.
logger
.
Infof
(
"peer %q connected"
,
i
.
Address
)
return
i
.
Address
,
nil
}
func
(
s
*
Service
)
Disconnect
(
overlay
string
)
error
{
peerID
,
found
:=
s
.
peers
.
peerID
(
overlay
)
if
!
found
{
return
p2p
.
ErrPeerNotFound
}
return
s
.
host
.
Network
()
.
ClosePeer
(
peerID
)
}
func
(
s
*
Service
)
NewStream
(
ctx
context
.
Context
,
overlay
,
protocolName
,
streamName
,
version
string
)
(
p2p
.
Stream
,
error
)
{
peerID
,
found
:=
s
.
peers
.
peerID
(
overlay
)
if
!
found
{
...
...
pkg/p2p/mock/mock.go
View file @
3839f3fa
...
...
@@ -6,7 +6,6 @@ package mock
import
(
"context"
"errors"
"fmt"
"io"
"sync"
...
...
@@ -16,19 +15,21 @@ import (
)
type
Service
struct
{
connectFunc
func
(
ctx
context
.
Context
,
addr
ma
.
Multiaddr
)
(
overlay
string
,
err
error
)
AddProtocolFunc
func
(
p2p
.
ProtocolSpec
)
error
ConnectFunc
func
(
ctx
context
.
Context
,
addr
ma
.
Multiaddr
)
(
overlay
string
,
err
error
)
DisconnectFunc
func
(
overlay
string
)
error
}
func
NewService
(
connectFunc
func
(
ctx
context
.
Context
,
addr
ma
.
Multiaddr
)
(
overlay
string
,
err
error
))
*
Service
{
return
&
Service
{
connectFunc
:
connectFunc
}
func
(
s
*
Service
)
AddProtocol
(
spec
p2p
.
ProtocolSpec
)
error
{
return
s
.
AddProtocolFunc
(
spec
)
}
func
(
s
*
Service
)
AddProtocol
(
_
p2p
.
ProtocolSpec
)
error
{
return
errors
.
New
(
"not implemented"
)
func
(
s
*
Service
)
Connect
(
ctx
context
.
Context
,
addr
ma
.
Multiaddr
)
(
overlay
string
,
err
error
)
{
return
s
.
ConnectFunc
(
ctx
,
addr
)
}
func
(
s
*
Service
)
Connect
(
ctx
context
.
Context
,
addr
ma
.
Multiaddr
)
(
overlay
string
,
err
error
)
{
return
s
.
connectFunc
(
ctx
,
addr
)
func
(
s
*
Service
)
Disconnect
(
overlay
string
)
error
{
return
s
.
DisconnectFunc
(
overlay
)
}
type
Recorder
struct
{
...
...
pkg/p2p/p2p.go
View file @
3839f3fa
...
...
@@ -15,6 +15,7 @@ import (
type
Service
interface
{
AddProtocol
(
ProtocolSpec
)
error
Connect
(
ctx
context
.
Context
,
addr
ma
.
Multiaddr
)
(
overlay
string
,
err
error
)
Disconnect
(
overlay
string
)
error
}
type
Streamer
interface
{
...
...
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