Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
migrate to consolidated types. (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
raulk authored May 26, 2019
1 parent 00a2b6a commit 91559fb
Show file tree
Hide file tree
Showing 16 changed files with 268 additions and 220 deletions.
9 changes: 5 additions & 4 deletions chat-with-mdns/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ import (
"os"

"github.com/libp2p/go-libp2p"
"github.com/libp2p/go-libp2p-crypto"
inet "github.com/libp2p/go-libp2p-net"
protocol "github.com/libp2p/go-libp2p-protocol"
"github.com/libp2p/go-libp2p-core/crypto"
"github.com/libp2p/go-libp2p-core/network"
"github.com/libp2p/go-libp2p-core/protocol"

"github.com/multiformats/go-multiaddr"
)

func handleStream(stream inet.Stream) {
func handleStream(stream network.Stream) {
fmt.Println("Got a new stream!")

// Create a buffer stream for non blocking read and write.
Expand Down
12 changes: 6 additions & 6 deletions chat-with-mdns/mdns.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ import (
"context"
"time"

host "github.com/libp2p/go-libp2p-host"
pstore "github.com/libp2p/go-libp2p-peerstore"
"github.com/libp2p/go-libp2p-core/host"
"github.com/libp2p/go-libp2p-core/peer"
"github.com/libp2p/go-libp2p/p2p/discovery"
)

type discoveryNotifee struct {
PeerChan chan pstore.PeerInfo
PeerChan chan peer.AddrInfo
}

//interface to be called when new peer is found
func (n *discoveryNotifee) HandlePeerFound(pi pstore.PeerInfo) {
func (n *discoveryNotifee) HandlePeerFound(pi peer.AddrInfo) {
n.PeerChan <- pi
}

//Initialize the MDNS service
func initMDNS(ctx context.Context, peerhost host.Host, rendezvous string) chan pstore.PeerInfo {
func initMDNS(ctx context.Context, peerhost host.Host, rendezvous string) chan peer.AddrInfo {
// An hour might be a long long period in practical applications. But this is fine for us
ser, err := discovery.NewMdnsService(ctx, peerhost, time.Hour, rendezvous)
if err != nil {
Expand All @@ -28,7 +28,7 @@ func initMDNS(ctx context.Context, peerhost host.Host, rendezvous string) chan p

//register with service so that we get notified about peer discovery
n := &discoveryNotifee{}
n.PeerChan = make(chan pstore.PeerInfo)
n.PeerChan = make(chan peer.AddrInfo)

ser.RegisterNotifee(n)
return n.PeerChan
Expand Down
18 changes: 10 additions & 8 deletions chat-with-rendezvous/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,22 @@ import (
"os"
"sync"

"github.com/ipfs/go-log"
"github.com/libp2p/go-libp2p"
"github.com/libp2p/go-libp2p-core/network"
"github.com/libp2p/go-libp2p-core/peer"
"github.com/libp2p/go-libp2p-core/protocol"
"github.com/libp2p/go-libp2p-discovery"
libp2pdht "github.com/libp2p/go-libp2p-kad-dht"
inet "github.com/libp2p/go-libp2p-net"
"github.com/libp2p/go-libp2p-peerstore"
"github.com/libp2p/go-libp2p-protocol"

dht "github.com/libp2p/go-libp2p-kad-dht"
multiaddr "github.com/multiformats/go-multiaddr"
logging "github.com/whyrusleeping/go-logging"

"github.com/ipfs/go-log"
)

var logger = log.Logger("rendezvous")

func handleStream(stream inet.Stream) {
func handleStream(stream network.Stream) {
logger.Info("Got a new stream!")

// Create a buffer stream for non blocking read and write.
Expand Down Expand Up @@ -115,7 +117,7 @@ func main() {
// client because we want each peer to maintain its own local copy of the
// DHT, so that the bootstrapping node of the DHT can go down without
// inhibiting future peer discovery.
kademliaDHT, err := libp2pdht.New(ctx, host)
kademliaDHT, err := dht.New(ctx, host)
if err != nil {
panic(err)
}
Expand All @@ -131,7 +133,7 @@ func main() {
// other nodes in the network.
var wg sync.WaitGroup
for _, peerAddr := range config.BootstrapPeers {
peerinfo, _ := peerstore.InfoFromP2pAddr(peerAddr)
peerinfo, _ := peer.AddrInfoFromP2pAddr(peerAddr)
wg.Add(1)
go func() {
defer wg.Done()
Expand Down
13 changes: 7 additions & 6 deletions chat/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
* This program demonstrate a simple chat application using p2p communication.
*
*/

package main

import (
Expand All @@ -40,13 +39,15 @@ import (
"os"

"github.com/libp2p/go-libp2p"
"github.com/libp2p/go-libp2p-crypto"
"github.com/libp2p/go-libp2p-net"
"github.com/libp2p/go-libp2p-peerstore"
"github.com/libp2p/go-libp2p-core/crypto"
"github.com/libp2p/go-libp2p-core/network"
"github.com/libp2p/go-libp2p-core/peer"
"github.com/libp2p/go-libp2p-core/peerstore"

"github.com/multiformats/go-multiaddr"
)

func handleStream(s net.Stream) {
func handleStream(s network.Stream) {
log.Println("Got a new stream!")

// Create a buffer stream for non blocking read and write.
Expand Down Expand Up @@ -178,7 +179,7 @@ func main() {
}

// Extract the peer ID from the multiaddr.
info, err := peerstore.InfoFromP2pAddr(maddr)
info, err := peer.AddrInfoFromP2pAddr(maddr)
if err != nil {
log.Fatalln(err)
}
Expand Down
19 changes: 10 additions & 9 deletions echo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ import (
"log"
mrand "math/rand"

"github.com/libp2p/go-libp2p"
"github.com/libp2p/go-libp2p-core/crypto"
"github.com/libp2p/go-libp2p-core/host"
"github.com/libp2p/go-libp2p-core/network"
"github.com/libp2p/go-libp2p-core/peer"
"github.com/libp2p/go-libp2p-core/peerstore"

golog "github.com/ipfs/go-log"
libp2p "github.com/libp2p/go-libp2p"
crypto "github.com/libp2p/go-libp2p-crypto"
host "github.com/libp2p/go-libp2p-host"
net "github.com/libp2p/go-libp2p-net"
peer "github.com/libp2p/go-libp2p-peer"
pstore "github.com/libp2p/go-libp2p-peerstore"
ma "github.com/multiformats/go-multiaddr"
gologging "github.com/whyrusleeping/go-logging"
)
Expand Down Expand Up @@ -100,7 +101,7 @@ func main() {

// Set a stream handler on host A. /echo/1.0.0 is
// a user-defined protocol name.
ha.SetStreamHandler("/echo/1.0.0", func(s net.Stream) {
ha.SetStreamHandler("/echo/1.0.0", func(s network.Stream) {
log.Println("Got a new stream!")
if err := doEcho(s); err != nil {
log.Println(err)
Expand Down Expand Up @@ -141,7 +142,7 @@ func main() {

// We have a peer ID and a targetAddr so we add it to the peerstore
// so LibP2P knows how to contact it
ha.Peerstore().AddAddr(peerid, targetAddr, pstore.PermanentAddrTTL)
ha.Peerstore().AddAddr(peerid, targetAddr, peerstore.PermanentAddrTTL)

log.Println("opening stream")
// make a new stream from host B to host A
Expand All @@ -166,7 +167,7 @@ func main() {
}

// doEcho reads a line of data a stream and writes it back
func doEcho(s net.Stream) error {
func doEcho(s network.Stream) error {
buf := bufio.NewReader(s)
str, err := buf.ReadString('\n')
if err != nil {
Expand Down
22 changes: 8 additions & 14 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
module github.com/libp2p/go-libp2p-examples

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gogo/protobuf v1.2.1
github.com/google/uuid v1.1.1
github.com/ipfs/go-datastore v0.0.1
github.com/ipfs/go-datastore v0.0.5
github.com/ipfs/go-log v0.0.1
github.com/libp2p/go-libp2p v0.0.1
github.com/libp2p/go-libp2p-circuit v0.0.1
github.com/libp2p/go-libp2p-crypto v0.0.1
github.com/libp2p/go-libp2p-discovery v0.0.1
github.com/libp2p/go-libp2p-host v0.0.1
github.com/libp2p/go-libp2p-kad-dht v0.0.3
github.com/libp2p/go-libp2p-net v0.0.1
github.com/libp2p/go-libp2p-peer v0.0.1
github.com/libp2p/go-libp2p-peerstore v0.0.1
github.com/libp2p/go-libp2p-protocol v0.0.1
github.com/libp2p/go-libp2p-swarm v0.0.1
github.com/multiformats/go-multiaddr v0.0.1
github.com/libp2p/go-libp2p v0.1.0
github.com/libp2p/go-libp2p-circuit v0.1.0
github.com/libp2p/go-libp2p-core v0.0.1
github.com/libp2p/go-libp2p-discovery v0.1.0
github.com/libp2p/go-libp2p-kad-dht v0.1.0
github.com/libp2p/go-libp2p-swarm v0.1.0
github.com/multiformats/go-multiaddr v0.0.4
github.com/multiformats/go-multiaddr-net v0.0.1
github.com/whyrusleeping/go-logging v0.0.0-20170515211332-0457bb6b88fc
)
Loading

0 comments on commit 91559fb

Please sign in to comment.