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
cab16ee4
Commit
cab16ee4
authored
8 years ago
by
Jeromy Johnson
Committed by
GitHub
8 years ago
Browse files
Options
Download
Plain Diff
Merge pull request #99 from libp2p/feat/pass-smux
swarm: pass in stream muxer on construct
parents
04b3077f
a56440a9
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
examples/justtcp/main.go
+7
-33
examples/justtcp/main.go
p2p/net/swarm/swarm.go
+2
-2
p2p/net/swarm/swarm.go
package.json
+2
-2
package.json
with
11 additions
and
37 deletions
+11
-37
examples/justtcp/main.go
View file @
cab16ee4
...
...
@@ -3,12 +3,10 @@ package main
import
(
"context"
"fmt"
"net"
"os"
transport
"github.com/ipfs/go-libp2p-transport"
ma
"github.com/jbenet/go-multiaddr"
smux
"github.com/jbenet/go-stream-muxer"
"github.com/libp2p/go-libp2p/p2p/net/swarm"
)
...
...
@@ -17,52 +15,27 @@ func fatal(i interface{}) {
os
.
Exit
(
1
)
}
type
NullMux
struct
{}
type
NullMuxConn
struct
{
net
.
Conn
}
func
(
c
*
NullMuxConn
)
AcceptStream
()
(
smux
.
Stream
,
error
)
{
panic
(
"We don't do this"
)
}
func
(
c
*
NullMuxConn
)
IsClosed
()
bool
{
return
false
}
func
(
c
*
NullMuxConn
)
OpenStream
()
(
smux
.
Stream
,
error
)
{
panic
(
"if only you could see how disappointed i am in you right now"
)
}
func
(
c
*
NullMuxConn
)
Serve
(
_
smux
.
StreamHandler
)
{
}
func
(
nm
NullMux
)
NewConn
(
c
net
.
Conn
,
server
bool
)
(
smux
.
Conn
,
error
)
{
return
&
NullMuxConn
{
c
},
nil
}
var
_
smux
.
Transport
=
(
*
NullMux
)(
nil
)
func
main
()
{
laddr
,
err
:=
ma
.
NewMultiaddr
(
"/ip4/0.0.0.0/tcp/5555"
)
if
err
!=
nil
{
fatal
(
err
)
}
swarm
.
PSTransport
=
new
(
NullMux
)
s
:=
swarm
.
NewBlankSwarm
(
context
.
Background
(),
"bob"
,
nil
)
// create a new swarm with a dummy peer ID, no private key, and no stream muxer
s
:=
swarm
.
NewBlankSwarm
(
context
.
Background
(),
"bob"
,
nil
,
nil
)
// Add a TCP transport to it
s
.
AddTransport
(
transport
.
NewTCPTransport
())
// Add an address to start listening on
err
=
s
.
AddListenAddr
(
laddr
)
if
err
!=
nil
{
fatal
(
err
)
}
// Set a handler for incoming connections
s
.
SetConnHandler
(
func
(
c
*
swarm
.
Conn
)
{
fmt
.
Println
(
"
CALLED OUR CONN HANDLER
!"
)
fmt
.
Println
(
"
Got a new connection
!"
)
defer
c
.
Close
()
buf
:=
make
([]
byte
,
1024
)
for
{
...
...
@@ -81,5 +54,6 @@ func main() {
}
})
// Wait forever
<-
make
(
chan
bool
)
}
This diff is collapsed.
Click to expand it.
p2p/net/swarm/swarm.go
View file @
cab16ee4
...
...
@@ -145,9 +145,9 @@ func NewSwarm(ctx context.Context, listenAddrs []ma.Multiaddr,
return
s
,
nil
}
func
NewBlankSwarm
(
ctx
context
.
Context
,
id
peer
.
ID
,
privkey
ci
.
PrivKey
)
*
Swarm
{
func
NewBlankSwarm
(
ctx
context
.
Context
,
id
peer
.
ID
,
privkey
ci
.
PrivKey
,
pstpt
pst
.
Transport
)
*
Swarm
{
s
:=
&
Swarm
{
swarm
:
ps
.
NewSwarm
(
PSTranspor
t
),
swarm
:
ps
.
NewSwarm
(
pstp
t
),
local
:
id
,
peers
:
pstore
.
NewPeerstore
(),
ctx
:
ctx
,
...
...
This diff is collapsed.
Click to expand it.
package.json
View file @
cab16ee4
...
...
@@ -129,9 +129,9 @@
"version"
:
"0.0.0"
},
{
"hash"
:
"Qm
duCCgTaLnxwwf9RFQy2PMUytrKcEH9msohtVxSBZUdgu
"
,
"hash"
:
"Qm
RmFKJgjjQhrT1uDyhpS87kE5M9YbMT8RBWam5uk8o4uH
"
,
"name"
:
"go-peerstream"
,
"version"
:
"1.
0
.0"
"version"
:
"1.
1
.0"
},
{
"author"
:
"whyrusleeping"
,
...
...
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