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-swarm
Commits
3676e634
Commit
3676e634
authored
Jun 24, 2018
by
Cole Brown
Committed by
Steven Allen
Aug 27, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update addStream/Conn to accept a Direction
parent
cdade26f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
8 additions
and
10 deletions
+8
-10
swarm.go
swarm.go
+2
-1
swarm_conn.go
swarm_conn.go
+4
-5
swarm_dial.go
swarm_dial.go
+1
-2
swarm_listen.go
swarm_listen.go
+1
-2
No files found.
swarm.go
View file @
3676e634
...
...
@@ -165,7 +165,7 @@ func (s *Swarm) Process() goprocess.Process {
return
s
.
proc
}
func
(
s
*
Swarm
)
addConn
(
tc
transport
.
Conn
,
stat
inet
.
Stat
)
(
*
Conn
,
error
)
{
func
(
s
*
Swarm
)
addConn
(
tc
transport
.
Conn
,
dir
inet
.
Direction
)
(
*
Conn
,
error
)
{
// The underlying transport (or the dialer) *should* filter it's own
// connections but we should double check anyways.
raddr
:=
tc
.
RemoteMultiaddr
()
...
...
@@ -194,6 +194,7 @@ func (s *Swarm) addConn(tc transport.Conn, stat inet.Stat) (*Conn, error) {
}
// Wrap and register the connection.
stat
:=
inet
.
Stat
{
Direction
:
dir
}
c
:=
&
Conn
{
conn
:
tc
,
swarm
:
s
,
...
...
swarm_conn.go
View file @
3676e634
...
...
@@ -100,8 +100,7 @@ func (c *Conn) start() {
}
c
.
swarm
.
refs
.
Add
(
1
)
go
func
()
{
stat
:=
inet
.
Stat
{
Direction
:
inet
.
DirInbound
}
s
,
err
:=
c
.
addStream
(
ts
,
stat
)
s
,
err
:=
c
.
addStream
(
ts
,
inet
.
DirInbound
)
// Don't defer this. We don't want to block
// swarm shutdown on the connection handler.
...
...
@@ -172,11 +171,10 @@ func (c *Conn) NewStream() (inet.Stream, error) {
if
err
!=
nil
{
return
nil
,
err
}
stat
:=
inet
.
Stat
{
Direction
:
inet
.
DirOutbound
}
return
c
.
addStream
(
ts
,
stat
)
return
c
.
addStream
(
ts
,
inet
.
DirOutbound
)
}
func
(
c
*
Conn
)
addStream
(
ts
smux
.
Stream
,
stat
inet
.
Stat
)
(
*
Stream
,
error
)
{
func
(
c
*
Conn
)
addStream
(
ts
smux
.
Stream
,
dir
inet
.
Direction
)
(
*
Stream
,
error
)
{
c
.
streams
.
Lock
()
// Are we still online?
if
c
.
streams
.
m
==
nil
{
...
...
@@ -186,6 +184,7 @@ func (c *Conn) addStream(ts smux.Stream, stat inet.Stat) (*Stream, error) {
}
// Wrap and register the stream.
stat
:=
inet
.
Stat
{
Direction
:
dir
}
s
:=
&
Stream
{
stream
:
ts
,
conn
:
c
,
...
...
swarm_dial.go
View file @
3676e634
...
...
@@ -325,8 +325,7 @@ func (s *Swarm) dial(ctx context.Context, p peer.ID) (*Conn, error) {
"localAddr"
:
connC
.
LocalMultiaddr
(),
"remoteAddr"
:
connC
.
RemoteMultiaddr
(),
}
stat
:=
inet
.
Stat
{
Direction
:
inet
.
DirOutbound
}
swarmC
,
err
:=
s
.
addConn
(
connC
,
stat
)
swarmC
,
err
:=
s
.
addConn
(
connC
,
inet
.
DirOutbound
)
if
err
!=
nil
{
logdial
[
"error"
]
=
err
.
Error
()
connC
.
Close
()
// close the connection. didn't work out :(
...
...
swarm_listen.go
View file @
3676e634
...
...
@@ -81,8 +81,7 @@ func (s *Swarm) AddListenAddr(a ma.Multiaddr) error {
s
.
refs
.
Add
(
1
)
go
func
()
{
defer
s
.
refs
.
Done
()
stat
:=
inet
.
Stat
{
Direction
:
inet
.
DirInbound
}
_
,
err
:=
s
.
addConn
(
c
,
stat
)
_
,
err
:=
s
.
addConn
(
c
,
inet
.
DirInbound
)
if
err
!=
nil
{
// Probably just means that the swarm has been closed.
log
.
Warningf
(
"add conn failed: "
,
err
)
...
...
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