Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
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
5a704d2d
Commit
5a704d2d
authored
6 years ago
by
Cole Brown
Committed by
Steven Allen
6 years ago
Browse files
Options
Download
Email Patches
Plain Diff
Add Stat to mock net conns and streams
parent
10a44085
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
p2p/net/mock/mock_conn.go
+8
-1
p2p/net/mock/mock_conn.go
p2p/net/mock/mock_link.go
+4
-4
p2p/net/mock/mock_link.go
p2p/net/mock/mock_stream.go
+7
-1
p2p/net/mock/mock_stream.go
with
19 additions
and
6 deletions
+19
-6
p2p/net/mock/mock_conn.go
View file @
5a704d2d
...
...
@@ -29,14 +29,16 @@ type conn struct {
rconn
*
conn
// counterpart
streams
list
.
List
proc
process
.
Process
stat
inet
.
Stat
sync
.
RWMutex
}
func
newConn
(
ln
,
rn
*
peernet
,
l
*
link
)
*
conn
{
func
newConn
(
ln
,
rn
*
peernet
,
l
*
link
,
dir
inet
.
Direction
)
*
conn
{
c
:=
&
conn
{
net
:
ln
,
link
:
l
}
c
.
local
=
ln
.
peer
c
.
remote
=
rn
.
peer
c
.
stat
=
inet
.
Stat
{
Direction
:
dir
}
c
.
localAddr
=
ln
.
ps
.
Addrs
(
ln
.
peer
)[
0
]
c
.
remoteAddr
=
rn
.
ps
.
Addrs
(
rn
.
peer
)[
0
]
...
...
@@ -155,3 +157,8 @@ func (c *conn) RemotePeer() peer.ID {
func
(
c
*
conn
)
RemotePublicKey
()
ic
.
PubKey
{
return
c
.
remotePubKey
}
// Stat returns metadata about the connection
func
(
c
*
conn
)
Stat
()
inet
.
Stat
{
return
c
.
stat
}
This diff is collapsed.
Click to expand it.
p2p/net/mock/mock_link.go
View file @
5a704d2d
...
...
@@ -33,8 +33,8 @@ func (l *link) newConnPair(dialer *peernet) (*conn, *conn) {
l
.
RLock
()
defer
l
.
RUnlock
()
c1
:=
newConn
(
l
.
nets
[
0
],
l
.
nets
[
1
],
l
)
c2
:=
newConn
(
l
.
nets
[
1
],
l
.
nets
[
0
],
l
)
c1
:=
newConn
(
l
.
nets
[
0
],
l
.
nets
[
1
],
l
,
inet
.
DirOutbound
)
c2
:=
newConn
(
l
.
nets
[
1
],
l
.
nets
[
0
],
l
,
inet
.
DirInbound
)
c1
.
rconn
=
c2
c2
.
rconn
=
c1
...
...
@@ -48,8 +48,8 @@ func (l *link) newStreamPair() (*stream, *stream) {
ra
,
wb
:=
io
.
Pipe
()
rb
,
wa
:=
io
.
Pipe
()
sa
:=
NewStream
(
wa
,
ra
)
sb
:=
NewStream
(
wb
,
rb
)
sa
:=
NewStream
(
wa
,
ra
,
inet
.
DirOutbound
)
sb
:=
NewStream
(
wb
,
rb
,
inet
.
DirInbound
)
return
sa
,
sb
}
...
...
This diff is collapsed.
Click to expand it.
p2p/net/mock/mock_stream.go
View file @
5a704d2d
...
...
@@ -25,6 +25,7 @@ type stream struct {
writeErr
error
protocol
protocol
.
ID
stat
inet
.
Stat
}
var
ErrReset
error
=
errors
.
New
(
"stream reset"
)
...
...
@@ -35,7 +36,7 @@ type transportObject struct {
arrivalTime
time
.
Time
}
func
NewStream
(
w
*
io
.
PipeWriter
,
r
*
io
.
PipeReader
)
*
stream
{
func
NewStream
(
w
*
io
.
PipeWriter
,
r
*
io
.
PipeReader
,
dir
inet
.
Direction
)
*
stream
{
s
:=
&
stream
{
read
:
r
,
write
:
w
,
...
...
@@ -43,6 +44,7 @@ func NewStream(w *io.PipeWriter, r *io.PipeReader) *stream {
close
:
make
(
chan
struct
{},
1
),
closed
:
make
(
chan
struct
{}),
toDeliver
:
make
(
chan
*
transportObject
),
stat
:
inet
.
Stat
{
Direction
:
dir
},
}
go
s
.
transport
()
...
...
@@ -66,6 +68,10 @@ func (s *stream) Protocol() protocol.ID {
return
s
.
protocol
}
func
(
s
*
stream
)
Stat
()
inet
.
Stat
{
return
s
.
stat
}
func
(
s
*
stream
)
SetProtocol
(
proto
protocol
.
ID
)
{
s
.
protocol
=
proto
}
...
...
This diff is collapsed.
Click to expand it.
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
Menu
Projects
Groups
Snippets
Help