Commit 4ea04c23 authored by vyzo's avatar vyzo
Browse files

identify: implement identify push protocol

parent 2b6c3a22
......@@ -3,6 +3,7 @@ package identify
import (
"context"
"sync"
"time"
pb "github.com/libp2p/go-libp2p/p2p/protocol/identify/pb"
......@@ -23,6 +24,9 @@ var log = logging.Logger("net/identify")
// ID is the protocol.ID of the Identify Service.
const ID = "/ipfs/id/1.0.0"
// IDPush is the protocol.ID of the Identify push protocol
const IDPush = "/ipfs/id/push/1.0.0"
// LibP2PVersion holds the current protocol version for a client running this code
// TODO(jbenet): fix the versioning mess.
const LibP2PVersion = "ipfs/0.1.0"
......@@ -60,6 +64,7 @@ func NewIDService(h host.Host) *IDService {
currid: make(map[inet.Conn]chan struct{}),
}
h.SetStreamHandler(ID, s.requestHandler)
h.SetStreamHandler(IDPush, s.pushHandler)
h.Network().Notify((*netNotifiee)(s))
return s
}
......@@ -138,6 +143,24 @@ func (ids *IDService) responseHandler(s inet.Stream) {
go inet.FullClose(s)
}
func (ids *IDService) pushHandler(s inet.Stream) {
ids.responseHandler(s)
}
func (ids *IDService) Push() {
for _, p := range ids.Host.Network().Peers() {
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
s, err := ids.Host.NewStream(ctx, p, IDPush)
cancel()
if err != nil {
log.Debugf("error opening push stream: %s", err.Error())
continue
}
ids.requestHandler(s)
}
}
func (ids *IDService) populateMessage(mes *pb.Identify, c inet.Conn) {
// set protocols this node is currently handling
......
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