identify: implement identify push protocol
This commit is contained in:
parent
2b6c3a228e
commit
4ea04c23b3
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue