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
eeddac93
Unverified
Commit
eeddac93
authored
Aug 28, 2018
by
Steven Allen
Committed by
GitHub
Aug 28, 2018
Browse files
Merge pull request #369 from libp2p/feat/stat
Add Stat to mock net conns and streams
parents
cacf6f42
5a704d2d
Changes
4
Hide whitespace changes
Inline
Side-by-side
p2p/net/mock/mock_conn.go
View file @
eeddac93
...
...
@@ -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
}
p2p/net/mock/mock_link.go
View file @
eeddac93
...
...
@@ -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
}
...
...
p2p/net/mock/mock_stream.go
View file @
eeddac93
...
...
@@ -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
}
...
...
package.json
View file @
eeddac93
...
...
@@ -61,9 +61,9 @@
},
{
"author"
:
"whyrusleeping"
,
"hash"
:
"QmW
KKkNLFRcznF5vDqt2eeRsnQqQhwbjVf8zJ9KC2RXrzN
"
,
"hash"
:
"QmW
ri2HWdxHjWBUermhWy7QWJqN1cV8Gd1QbDiB5m86f1H
"
,
"name"
:
"go-libp2p-secio"
,
"version"
:
"2.0.
7
"
"version"
:
"2.0.
8
"
},
{
"author"
:
"whyrusleeping"
,
...
...
@@ -73,15 +73,15 @@
},
{
"author"
:
"whyrusleeping"
,
"hash"
:
"Qm
Yr9RHifaqHTFZdAsUPLmiMAi2oNeEqA48AFKxXJAsLpJ
"
,
"hash"
:
"Qm
cDUyb52N62J8ZamGgUWUyWc1MtuCBce7WFA4D9xA6cwF
"
,
"name"
:
"go-libp2p-transport"
,
"version"
:
"3.0.
7
"
"version"
:
"3.0.
8
"
},
{
"author"
:
"whyrusleeping"
,
"hash"
:
"Qmc
K89iqkFV8TqpRUgx1481YZbhjPFnBjqkpBQJfJqmSfm
"
,
"hash"
:
"Qmc
w9fndogcYwyGs4a5TPDbnZPBLxvtrBZzpvyyVDzxDWT
"
,
"name"
:
"go-tcp-transport"
,
"version"
:
"2.0.
7
"
"version"
:
"2.0.
8
"
},
{
"author"
:
"whyrusleeping"
,
...
...
@@ -103,9 +103,9 @@
},
{
"author"
:
"whyrusleeping"
,
"hash"
:
"Qm
X5J1q63BrrDTbpcHifrFbxH3cMZsvaNajy6u3zCpzBXs
"
,
"hash"
:
"Qm
QSbtGXCyNrj34LWL8EgXyNNYDZ8r3SwQcpW5pPxVhLnM
"
,
"name"
:
"go-libp2p-net"
,
"version"
:
"3.0.
7
"
"version"
:
"3.0.
8
"
},
{
"author"
:
"whyrusleeping"
,
...
...
@@ -115,15 +115,15 @@
},
{
"author"
:
"whyrusleeping"
,
"hash"
:
"Qm
RRCrNRs4qxotXx7WJT6SpCvSNEhXvyBcVjXY2K71pcjE
"
,
"hash"
:
"Qm
PMtD39NN63AEUNghk1LFQcTLcCmYL8MtRzdv8BRUsC4Z
"
,
"name"
:
"go-libp2p-host"
,
"version"
:
"3.0.
6
"
"version"
:
"3.0.
7
"
},
{
"author"
:
"whyrusleeping"
,
"hash"
:
"Qm
PWNZRUybw3nwJH3mpkrwB97YEQmXRkzvyh34rpJiih6Q
"
,
"hash"
:
"Qm
YSM6PKnCe9YVPNMisfpoBmczzHkA7h5Wrnc36DtdJhGo
"
,
"name"
:
"go-libp2p-swarm"
,
"version"
:
"3.0.
8
"
"version"
:
"3.0.
9
"
},
{
"author"
:
"whyrusleeping"
,
...
...
@@ -139,9 +139,9 @@
},
{
"author"
:
"whyrusleeping"
,
"hash"
:
"Qm
RAsmNHjzKVuscipvMVjB3NTyLW1HTBiSP8LaKD1iUJmH
"
,
"hash"
:
"Qm
bKt1yZEnCWUmQhZR9BMiXK4e4FoaqnieAARz1s88MSzf
"
,
"name"
:
"go-libp2p-blankhost"
,
"version"
:
"0.3.
6
"
"version"
:
"0.3.
7
"
},
{
"author"
:
"whyrusleeping"
,
...
...
@@ -169,9 +169,9 @@
},
{
"author"
:
"vyzo"
,
"hash"
:
"Qm
bc6WjgbkaYhPw5dd6X2RLGiJz854dPPKkyZf52vE2PTS
"
,
"hash"
:
"Qm
VYqPFBGi5wiuxpKxf4mUePEDdfXh8H7HKtq4mH8SeqML
"
,
"name"
:
"go-libp2p-circuit"
,
"version"
:
"2.1.
9
"
"version"
:
"2.1.
10
"
},
{
"author"
:
"lgierth"
,
...
...
@@ -181,9 +181,9 @@
},
{
"author"
:
"why"
,
"hash"
:
"Qm
UPz6FCzCCU7sTY9Sore5NGSUA8YSF2yMkLPjDFq7wGqD
"
,
"hash"
:
"Qm
Vz2p8ZVZ5GcWPNWGs2HZHiZyHumZcJpQdMRpxkMDhc2C
"
,
"name"
:
"go-libp2p-interface-connmgr"
,
"version"
:
"0.0.1
3
"
"version"
:
"0.0.1
4
"
},
{
"author"
:
"whyrusleeping"
,
...
...
@@ -193,21 +193,21 @@
},
{
"author"
:
"whyrusleeping"
,
"hash"
:
"Qm
TDv8XeECZaYBZXo5SAEGueMiPTszAkGZQ5YiM5KCAJai
"
,
"hash"
:
"Qm
SQhZyqoEepHPHr6kCpAoYVHzvVkTHAAXnNqFEFbVaaQr
"
,
"name"
:
"go-ws-transport"
,
"version"
:
"2.0.
7
"
"version"
:
"2.0.
8
"
},
{
"author"
:
"stebalien"
,
"hash"
:
"Qm
a6UXLMHjdVFExQZLYqdb5KAesbnoXuthQzovrwRZ64fG
"
,
"hash"
:
"Qm
SbkqfiFmJCdczVQ7mkFZf5FUUNpuP5Ne2LxY2htXGtrZ
"
,
"name"
:
"go-conn-security-multistream"
,
"version"
:
"0.1.
6
"
"version"
:
"0.1.
7
"
},
{
"author"
:
"Stebalien"
,
"hash"
:
"Qm
cGgFLHMFLcNMMvxsBC5LeLqubLR5djxjShVU3koVMtVq
"
,
"hash"
:
"Qm
NPQvc3jUA7L6oHB8en9PittPGazFMdoveN2oycHL6yWF
"
,
"name"
:
"go-conn-security"
,
"version"
:
"0.1.
7
"
"version"
:
"0.1.
8
"
},
{
"author"
:
"libp2p"
,
...
...
@@ -223,9 +223,9 @@
},
{
"author"
:
"steb"
,
"hash"
:
"Qm
fNvpHX396fhMeauERV6eFnSJg78rUjhjpFf1JvbjxaYM
"
,
"hash"
:
"Qm
efQrpDSYX6jQRtUyhcASFVBDkoAsDTPXemyxGMzA3phK
"
,
"name"
:
"go-libp2p-transport-upgrader"
,
"version"
:
"0.1.
7
"
"version"
:
"0.1.
8
"
},
{
"hash"
:
"QmdxUuburamoF6zF9qjeQC4WYcWGbWuRmdLacMEsW8ioD8"
,
...
...
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