Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
p2p
go-p2p
Commits
985120b6
Unverified
Commit
985120b6
authored
Jun 16, 2020
by
Raúl Kripalani
Committed by
GitHub
Jun 16, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
upgrade swarm; add ID() on mock conns and streams. (#970)
parent
14f4ff5e
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
56 additions
and
55 deletions
+56
-55
go.mod
go.mod
+2
-4
go.sum
go.sum
+34
-51
p2p/net/mock/mock_conn.go
p2p/net/mock/mock_conn.go
+11
-0
p2p/net/mock/mock_stream.go
p2p/net/mock/mock_stream.go
+9
-0
No files found.
go.mod
View file @
985120b6
...
...
@@ -17,7 +17,7 @@ require (
github.com/libp2p/go-libp2p-autonat
v0.2.3
github.com/libp2p/go-libp2p-blankhost
v0.1.6
github.com/libp2p/go-libp2p-circuit
v0.2.3
github.com/libp2p/go-libp2p-core
v0.
5.7
github.com/libp2p/go-libp2p-core
v0.
6.0
github.com/libp2p/go-libp2p-discovery
v0.4.0
github.com/libp2p/go-libp2p-loggables
v0.1.0
github.com/libp2p/go-libp2p-mplex
v0.2.3
...
...
@@ -25,7 +25,7 @@ require (
github.com/libp2p/go-libp2p-netutil
v0.1.0
github.com/libp2p/go-libp2p-peerstore
v0.2.6
github.com/libp2p/go-libp2p-secio
v0.2.2
github.com/libp2p/go-libp2p-swarm
v0.2.
6
github.com/libp2p/go-libp2p-swarm
v0.2.
7
github.com/libp2p/go-libp2p-testing
v0.1.1
github.com/libp2p/go-libp2p-tls
v0.1.3
github.com/libp2p/go-libp2p-transport-upgrader
v0.3.0
...
...
@@ -41,6 +41,4 @@ require (
github.com/multiformats/go-multistream
v0.1.1
github.com/stretchr/testify
v1.6.1
github.com/whyrusleeping/mdns
v0.0.0-20190826153040-b9b60ed33aa9
golang.org/x/net
v0.0.0-20200519113804-d87ec0cfa476 // indirect
golang.org/x/sys
v0.0.0-20200519105757-fe76b779f299 // indirect
)
go.sum
View file @
985120b6
This diff is collapsed.
Click to expand it.
p2p/net/mock/mock_conn.go
View file @
985120b6
...
...
@@ -2,7 +2,9 @@ package mocknet
import
(
"container/list"
"strconv"
"sync"
"sync/atomic"
process
"github.com/jbenet/goprocess"
ic
"github.com/libp2p/go-libp2p-core/crypto"
...
...
@@ -12,12 +14,16 @@ import (
manet
"github.com/multiformats/go-multiaddr-net"
)
var
connCounter
int64
// conn represents one side's perspective of a
// live connection between two peers.
// it goes over a particular link.
type
conn
struct
{
notifLk
sync
.
Mutex
id
int64
local
peer
.
ID
remote
peer
.
ID
...
...
@@ -43,6 +49,7 @@ func newConn(p process.Process, ln, rn *peernet, l *link, dir network.Direction)
c
.
local
=
ln
.
peer
c
.
remote
=
rn
.
peer
c
.
stat
=
network
.
Stat
{
Direction
:
dir
}
c
.
id
=
atomic
.
AddInt64
(
&
connCounter
,
1
)
c
.
localAddr
=
ln
.
ps
.
Addrs
(
ln
.
peer
)[
0
]
for
_
,
a
:=
range
rn
.
ps
.
Addrs
(
rn
.
peer
)
{
...
...
@@ -61,6 +68,10 @@ func newConn(p process.Process, ln, rn *peernet, l *link, dir network.Direction)
return
c
}
func
(
c
*
conn
)
ID
()
string
{
return
strconv
.
FormatInt
(
c
.
id
,
10
)
}
func
(
c
*
conn
)
Close
()
error
{
return
c
.
pairProc
.
Close
()
}
...
...
p2p/net/mock/mock_stream.go
View file @
985120b6
...
...
@@ -5,6 +5,7 @@ import (
"errors"
"io"
"net"
"strconv"
"sync"
"sync/atomic"
"time"
...
...
@@ -14,12 +15,15 @@ import (
protocol
"github.com/libp2p/go-libp2p-core/protocol"
)
var
streamCounter
int64
// stream implements network.Stream
type
stream
struct
{
notifLk
sync
.
Mutex
rstream
*
stream
conn
*
conn
id
int64
write
*
io
.
PipeWriter
read
*
io
.
PipeReader
...
...
@@ -57,6 +61,7 @@ func newStream(w *io.PipeWriter, r *io.PipeReader, dir network.Direction) *strea
s
:=
&
stream
{
read
:
r
,
write
:
w
,
id
:
atomic
.
AddInt64
(
&
streamCounter
,
1
),
reset
:
make
(
chan
struct
{},
1
),
close
:
make
(
chan
struct
{},
1
),
closed
:
make
(
chan
struct
{}),
...
...
@@ -86,6 +91,10 @@ func (s *stream) Write(p []byte) (n int, err error) {
return
len
(
p
),
nil
}
func
(
s
*
stream
)
ID
()
string
{
return
strconv
.
FormatInt
(
s
.
id
,
10
)
}
func
(
s
*
stream
)
Protocol
()
protocol
.
ID
{
// Ignore type error. It means that the protocol is unset.
p
,
_
:=
s
.
protocol
.
Load
()
.
(
protocol
.
ID
)
...
...
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