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) {
...
@@ -24,12 +24,14 @@ func TestConnect(t *testing.T) {
testErr
:=
errors
.
New
(
"test error"
)
testErr
:=
errors
.
New
(
"test error"
)
client
,
cleanup
:=
newTestServer
(
t
,
testServerOptions
{
client
,
cleanup
:=
newTestServer
(
t
,
testServerOptions
{
P2P
:
mock
.
NewService
(
func
(
ctx
context
.
Context
,
addr
ma
.
Multiaddr
)
(
string
,
error
)
{
P2P
:
&
mock
.
Service
{
if
addr
.
String
()
==
errorUnderlay
{
ConnectFunc
:
func
(
ctx
context
.
Context
,
addr
ma
.
Multiaddr
)
(
string
,
error
)
{
return
""
,
testErr
if
addr
.
String
()
==
errorUnderlay
{
}
return
""
,
testErr
return
overlay
,
nil
}
}),
return
overlay
,
nil
},
},
})
})
defer
cleanup
()
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
...
@@ -327,6 +327,15 @@ func (s *Service) Connect(ctx context.Context, addr ma.Multiaddr) (overlay strin
s
.
logger
.
Infof
(
"peer %q connected"
,
i
.
Address
)
s
.
logger
.
Infof
(
"peer %q connected"
,
i
.
Address
)
return
i
.
Address
,
nil
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
)
{
func
(
s
*
Service
)
NewStream
(
ctx
context
.
Context
,
overlay
,
protocolName
,
streamName
,
version
string
)
(
p2p
.
Stream
,
error
)
{
peerID
,
found
:=
s
.
peers
.
peerID
(
overlay
)
peerID
,
found
:=
s
.
peers
.
peerID
(
overlay
)
if
!
found
{
if
!
found
{
...
...
pkg/p2p/mock/mock.go
View file @
3839f3fa
...
@@ -6,7 +6,6 @@ package mock
...
@@ -6,7 +6,6 @@ package mock
import
(
import
(
"context"
"context"
"errors"
"fmt"
"fmt"
"io"
"io"
"sync"
"sync"
...
@@ -16,19 +15,21 @@ import (
...
@@ -16,19 +15,21 @@ import (
)
)
type
Service
struct
{
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
{
func
(
s
*
Service
)
AddProtocol
(
spec
p2p
.
ProtocolSpec
)
error
{
return
&
Service
{
connectFunc
:
connectFunc
}
return
s
.
AddProtocolFunc
(
spec
)
}
}
func
(
s
*
Service
)
AddProtocol
(
_
p2p
.
ProtocolSpec
)
error
{
func
(
s
*
Service
)
Connect
(
ctx
context
.
Context
,
addr
ma
.
Multiaddr
)
(
overlay
string
,
err
error
)
{
return
errors
.
New
(
"not implemented"
)
return
s
.
ConnectFunc
(
ctx
,
addr
)
}
}
func
(
s
*
Service
)
Connect
(
ctx
context
.
Context
,
addr
ma
.
Multiaddr
)
(
overlay
string
,
err
error
)
{
func
(
s
*
Service
)
Disconnect
(
overlay
string
)
error
{
return
s
.
connectFunc
(
ctx
,
addr
)
return
s
.
DisconnectFunc
(
overlay
)
}
}
type
Recorder
struct
{
type
Recorder
struct
{
...
...
pkg/p2p/p2p.go
View file @
3839f3fa
...
@@ -15,6 +15,7 @@ import (
...
@@ -15,6 +15,7 @@ import (
type
Service
interface
{
type
Service
interface
{
AddProtocol
(
ProtocolSpec
)
error
AddProtocol
(
ProtocolSpec
)
error
Connect
(
ctx
context
.
Context
,
addr
ma
.
Multiaddr
)
(
overlay
string
,
err
error
)
Connect
(
ctx
context
.
Context
,
addr
ma
.
Multiaddr
)
(
overlay
string
,
err
error
)
Disconnect
(
overlay
string
)
error
}
}
type
Streamer
interface
{
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