go-libp2p-pubsub/gossipsub.go

81 lines
1.3 KiB
Go
Raw Normal View History

2018-02-16 22:01:15 +02:00
package floodsub
import (
"context"
2018-02-19 14:50:14 +02:00
"time"
2018-02-16 22:01:15 +02:00
pb "github.com/libp2p/go-floodsub/pb"
host "github.com/libp2p/go-libp2p-host"
peer "github.com/libp2p/go-libp2p-peer"
protocol "github.com/libp2p/go-libp2p-protocol"
)
const (
GossipSubID = protocol.ID("/meshsub/1.0.0")
)
func NewGossipSub(ctx context.Context, h host.Host, opts ...Option) (*PubSub, error) {
rt := &GossipSubRouter{}
return NewPubSub(ctx, h, rt, opts...)
}
type GossipSubRouter struct {
p *PubSub
}
func (fs *GossipSubRouter) Protocols() []protocol.ID {
return []protocol.ID{GossipSubID, FloodSubID}
}
func (fs *GossipSubRouter) Attach(p *PubSub) {
fs.p = p
2018-02-19 14:50:14 +02:00
go fs.heartbeatTimer()
2018-02-16 22:01:15 +02:00
}
func (fs *GossipSubRouter) AddPeer(peer.ID, protocol.ID) {
}
func (fs *GossipSubRouter) RemovePeer(peer.ID) {
}
func (fs *GossipSubRouter) HandleRPC(rpc *RPC) {
}
func (fs *GossipSubRouter) Publish(from peer.ID, msg *pb.Message) {
}
func (fs *GossipSubRouter) Join(topic string) {
}
func (fs *GossipSubRouter) Leave(topic string) {
}
2018-02-19 14:50:14 +02:00
func (fs *GossipSubRouter) heartbeatTimer() {
ticker := time.NewTicker(1 * time.Second)
defer ticker.Stop()
for {
select {
case <-ticker.C:
select {
case fs.p.eval <- fs.heartbeat:
case <-fs.p.ctx.Done():
return
}
case <-fs.p.ctx.Done():
return
}
}
}
func (fs *GossipSubRouter) heartbeat() {
}