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
8a7f9c86
Commit
8a7f9c86
authored
Aug 10, 2016
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update multistream deps and fix code to work with new changes
parent
1b9cb346
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
11 deletions
+30
-11
swarm.go
swarm.go
+2
-2
swarm_notif_test.go
swarm_notif_test.go
+8
-2
swarm_stream.go
swarm_stream.go
+20
-7
No files found.
swarm.go
View file @
8a7f9c86
...
@@ -340,9 +340,9 @@ func (n *ps2netNotifee) Disconnected(c *ps.Conn) {
...
@@ -340,9 +340,9 @@ func (n *ps2netNotifee) Disconnected(c *ps.Conn) {
}
}
func
(
n
*
ps2netNotifee
)
OpenedStream
(
s
*
ps
.
Stream
)
{
func
(
n
*
ps2netNotifee
)
OpenedStream
(
s
*
ps
.
Stream
)
{
n
.
not
.
OpenedStream
(
n
.
net
,
inet
.
Stream
((
*
S
tream
)(
s
))
)
n
.
not
.
OpenedStream
(
n
.
net
,
&
Stream
{
s
tream
:
s
}
)
}
}
func
(
n
*
ps2netNotifee
)
ClosedStream
(
s
*
ps
.
Stream
)
{
func
(
n
*
ps2netNotifee
)
ClosedStream
(
s
*
ps
.
Stream
)
{
n
.
not
.
ClosedStream
(
n
.
net
,
inet
.
Stream
((
*
S
tream
)(
s
))
)
n
.
not
.
ClosedStream
(
n
.
net
,
&
Stream
{
s
tream
:
s
}
)
}
}
swarm_notif_test.go
View file @
8a7f9c86
...
@@ -10,6 +10,12 @@ import (
...
@@ -10,6 +10,12 @@ import (
context
"golang.org/x/net/context"
context
"golang.org/x/net/context"
)
)
func
streamsSame
(
a
,
b
inet
.
Stream
)
bool
{
sa
:=
a
.
(
*
Stream
)
sb
:=
b
.
(
*
Stream
)
return
sa
.
Stream
()
==
sb
.
Stream
()
}
func
TestNotifications
(
t
*
testing
.
T
)
{
func
TestNotifications
(
t
*
testing
.
T
)
{
ctx
:=
context
.
Background
()
ctx
:=
context
.
Background
()
swarms
:=
makeSwarms
(
ctx
,
t
,
5
)
swarms
:=
makeSwarms
(
ctx
,
t
,
5
)
...
@@ -98,7 +104,7 @@ func TestNotifications(t *testing.T) {
...
@@ -98,7 +104,7 @@ func TestNotifications(t *testing.T) {
case
<-
time
.
After
(
timeout
)
:
case
<-
time
.
After
(
timeout
)
:
t
.
Fatal
(
"timeout"
)
t
.
Fatal
(
"timeout"
)
}
}
if
s
!=
s2
{
if
!
streamsSame
(
s
,
s2
)
{
t
.
Fatal
(
"got incorrect stream"
,
s
.
Conn
(),
s2
.
Conn
())
t
.
Fatal
(
"got incorrect stream"
,
s
.
Conn
(),
s2
.
Conn
())
}
}
...
@@ -108,7 +114,7 @@ func TestNotifications(t *testing.T) {
...
@@ -108,7 +114,7 @@ func TestNotifications(t *testing.T) {
case
<-
time
.
After
(
timeout
)
:
case
<-
time
.
After
(
timeout
)
:
t
.
Fatal
(
"timeout"
)
t
.
Fatal
(
"timeout"
)
}
}
if
s
!=
s2
{
if
!
streamsSame
(
s
,
s2
)
{
t
.
Fatal
(
"got incorrect stream"
,
s
.
Conn
(),
s2
.
Conn
())
t
.
Fatal
(
"got incorrect stream"
,
s
.
Conn
(),
s2
.
Conn
())
}
}
}
}
...
...
swarm_stream.go
View file @
8a7f9c86
...
@@ -8,11 +8,14 @@ import (
...
@@ -8,11 +8,14 @@ import (
// a Stream is a wrapper around a ps.Stream that exposes a way to get
// a Stream is a wrapper around a ps.Stream that exposes a way to get
// our Conn and Swarm (instead of just the ps.Conn and ps.Swarm)
// our Conn and Swarm (instead of just the ps.Conn and ps.Swarm)
type
Stream
ps
.
Stream
type
Stream
struct
{
stream
*
ps
.
Stream
protocol
string
}
// Stream returns the underlying peerstream.Stream
// Stream returns the underlying peerstream.Stream
func
(
s
*
Stream
)
Stream
()
*
ps
.
Stream
{
func
(
s
*
Stream
)
Stream
()
*
ps
.
Stream
{
return
(
*
p
s
.
S
tream
)(
s
)
return
s
.
s
tream
}
}
// Conn returns the Conn associated with this Stream, as an inet.Conn
// Conn returns the Conn associated with this Stream, as an inet.Conn
...
@@ -22,27 +25,37 @@ func (s *Stream) Conn() inet.Conn {
...
@@ -22,27 +25,37 @@ func (s *Stream) Conn() inet.Conn {
// SwarmConn returns the Conn associated with this Stream, as a *Conn
// SwarmConn returns the Conn associated with this Stream, as a *Conn
func
(
s
*
Stream
)
SwarmConn
()
*
Conn
{
func
(
s
*
Stream
)
SwarmConn
()
*
Conn
{
return
(
*
Conn
)(
s
.
S
tream
()
.
Conn
())
return
(
*
Conn
)(
s
.
s
tream
.
Conn
())
}
}
// Read reads bytes from a stream.
// Read reads bytes from a stream.
func
(
s
*
Stream
)
Read
(
p
[]
byte
)
(
n
int
,
err
error
)
{
func
(
s
*
Stream
)
Read
(
p
[]
byte
)
(
n
int
,
err
error
)
{
return
s
.
S
tream
()
.
Read
(
p
)
return
s
.
s
tream
.
Read
(
p
)
}
}
// Write writes bytes to a stream, flushing for each call.
// Write writes bytes to a stream, flushing for each call.
func
(
s
*
Stream
)
Write
(
p
[]
byte
)
(
n
int
,
err
error
)
{
func
(
s
*
Stream
)
Write
(
p
[]
byte
)
(
n
int
,
err
error
)
{
return
s
.
S
tream
()
.
Write
(
p
)
return
s
.
s
tream
.
Write
(
p
)
}
}
// Close closes the stream, indicating this side is finished
// Close closes the stream, indicating this side is finished
// with the stream.
// with the stream.
func
(
s
*
Stream
)
Close
()
error
{
func
(
s
*
Stream
)
Close
()
error
{
return
s
.
Stream
()
.
Close
()
return
s
.
stream
.
Close
()
}
func
(
s
*
Stream
)
Protocol
()
string
{
return
s
.
protocol
}
func
(
s
*
Stream
)
SetProtocol
(
p
string
)
{
s
.
protocol
=
p
}
}
func
wrapStream
(
pss
*
ps
.
Stream
)
*
Stream
{
func
wrapStream
(
pss
*
ps
.
Stream
)
*
Stream
{
return
(
*
Stream
)(
pss
)
return
&
Stream
{
stream
:
pss
,
}
}
}
func
wrapStreams
(
st
[]
*
ps
.
Stream
)
[]
*
Stream
{
func
wrapStreams
(
st
[]
*
ps
.
Stream
)
[]
*
Stream
{
...
...
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