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
ab39c6f5
Commit
ab39c6f5
authored
Sep 04, 2016
by
Jeromy
Browse files
don't use ipfsaddr
parent
f9cd03e6
Changes
1
Hide whitespace changes
Inline
Side-by-side
examples/hosts/main.go
View file @
ab39c6f5
...
@@ -5,16 +5,17 @@ import (
...
@@ -5,16 +5,17 @@ import (
"fmt"
"fmt"
"io/ioutil"
"io/ioutil"
"log"
"log"
"strings"
peer
"github.com/ipfs/go-libp2p-peer"
peer
"github.com/ipfs/go-libp2p-peer"
pstore
"github.com/ipfs/go-libp2p-peerstore"
pstore
"github.com/ipfs/go-libp2p-peerstore"
host
"github.com/libp2p/go-libp2p/p2p/host"
host
"github.com/libp2p/go-libp2p/p2p/host"
bhost
"github.com/libp2p/go-libp2p/p2p/host/basic"
bhost
"github.com/libp2p/go-libp2p/p2p/host/basic"
inet
"github.com/libp2p/go-libp2p/p2p/net"
net
"github.com/libp2p/go-libp2p/p2p/net"
net
"github.com/libp2p/go-libp2p/p2p/net"
swarm
"github.com/libp2p/go-libp2p/p2p/net/swarm"
swarm
"github.com/libp2p/go-libp2p/p2p/net/swarm"
testutil
"github.com/libp2p/go-libp2p/testutil"
testutil
"github.com/libp2p/go-libp2p/testutil"
ipfsaddr
"github.com/ipfs/go-ipfs/thirdparty/ipfsaddr"
ma
"github.com/jbenet/go-multiaddr"
ma
"github.com/jbenet/go-multiaddr"
context
"golang.org/x/net/context"
context
"golang.org/x/net/context"
)
)
...
@@ -84,14 +85,30 @@ func main() {
...
@@ -84,14 +85,30 @@ func main() {
select
{}
// hang forever
select
{}
// hang forever
}
}
a
,
err
:=
ipfsaddr
.
ParseString
(
*
target
)
ipfsaddr
,
err
:=
ma
.
NewMultiaddr
(
*
target
)
if
err
!=
nil
{
log
.
Fatalln
(
err
)
}
pid
,
err
:=
ipfsaddr
.
ValueForProtocol
(
ma
.
P_IPFS
)
if
err
!=
nil
{
log
.
Fatalln
(
err
)
}
peerid
,
err
:=
peer
.
IDB58Decode
(
pid
)
if
err
!=
nil
{
log
.
Fatalln
(
err
)
}
tptaddr
:=
strings
.
Split
(
ipfsaddr
.
String
(),
"/ipfs/"
)[
0
]
tptmaddr
,
err
:=
ma
.
NewMultiaddr
(
tptaddr
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Fatalln
(
err
)
log
.
Fatalln
(
err
)
}
}
pi
:=
pstore
.
PeerInfo
{
pi
:=
pstore
.
PeerInfo
{
ID
:
a
.
ID
()
,
ID
:
peerid
,
Addrs
:
[]
ma
.
Multiaddr
{
a
.
Transport
()
},
Addrs
:
[]
ma
.
Multiaddr
{
tptmaddr
},
}
}
log
.
Println
(
"connecting to target"
)
log
.
Println
(
"connecting to target"
)
...
@@ -103,7 +120,7 @@ func main() {
...
@@ -103,7 +120,7 @@ func main() {
log
.
Println
(
"opening stream..."
)
log
.
Println
(
"opening stream..."
)
// make a new stream from host B to host A
// make a new stream from host B to host A
// it should be handled on host A by the handler we set
// it should be handled on host A by the handler we set
s
,
err
:=
ha
.
NewStream
(
context
.
Background
(),
a
.
ID
()
,
"/hello/1.0.0"
)
s
,
err
:=
ha
.
NewStream
(
context
.
Background
(),
peerid
,
"/hello/1.0.0"
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Fatalln
(
err
)
log
.
Fatalln
(
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