Commit ab39c6f5 authored by Jeromy's avatar Jeromy
Browse files

don't use ipfsaddr

parent f9cd03e6
...@@ -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)
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment