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
5100dcec
Commit
5100dcec
authored
8 years ago
by
Jeromy
Browse files
Options
Download
Email Patches
Plain Diff
update hosts example
parent
00c29a79
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/hosts/main.go
+10
-5
examples/hosts/main.go
with
10 additions
and
5 deletions
+10
-5
examples/hosts/main.go
View file @
5100dcec
...
...
@@ -21,6 +21,12 @@ import (
context
"golang.org/x/net/context"
)
func
init
()
{
// Disable secio for this demo
// This makes testing with javascript easier
conn
.
EncryptConnections
=
false
}
// create a 'Host' with a random peer to listen on the given address
func
makeDummyHost
(
listen
string
)
(
host
.
Host
,
error
)
{
addr
,
err
:=
ma
.
NewMultiaddr
(
listen
)
...
...
@@ -47,7 +53,7 @@ func makeDummyHost(listen string) (host.Host, error) {
}
func
main
()
{
conn
.
EncryptConnections
=
false
listenF
:=
flag
.
Int
(
"l"
,
0
,
"wait for incoming connections"
)
target
:=
flag
.
String
(
"d"
,
""
,
"target peer to dial"
)
flag
.
Parse
()
...
...
@@ -60,6 +66,7 @@ func main() {
}
message
:=
[]
byte
(
"hello libp2p!"
)
// Set a stream handler on host A
ha
.
SetStreamHandler
(
"/hello/1.0.0"
,
func
(
s
net
.
Stream
)
{
defer
s
.
Close
()
...
...
@@ -68,10 +75,8 @@ func main() {
})
if
*
target
==
""
{
log
.
Println
(
"listening on for connections..."
)
for
{
time
.
Sleep
(
time
.
Hour
)
}
log
.
Println
(
"listening for connections..."
)
select
{}
// hang forever
}
a
,
err
:=
ipfsaddr
.
ParseString
(
*
target
)
...
...
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