Skip to content

Commit

Permalink
fix: subscribe to topic
Browse files Browse the repository at this point in the history
  • Loading branch information
atanmarko committed Dec 1, 2022
1 parent c39a6b6 commit f3ebb94
Show file tree
Hide file tree
Showing 5 changed files with 196 additions and 1 deletion.
1 change: 0 additions & 1 deletion network/frost/frost_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ func (s *FrostStream) Client(stream network.Stream) *network.Stream {
}

func (s *FrostStream) Handler() func(network.Stream) {

Check failure on line 35 in network/frost/frost_stream.go

View workflow job for this annotation

GitHub Actions / golangci_lint

unnecessary leading newline (whitespace)
fmt.Println(">>>>>>>>>>>>>>> FROST Handler called:")

return func(stream network.Stream) {
go func() {
Expand Down
152 changes: 152 additions & 0 deletions network/frost/proto/frost.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions network/frost/proto/frost.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
syntax = "proto3";

package v1;

option go_package = "/frost/proto";

// Block contains a block data
message FrostMessage {
string message = 1;
string number = 2;
}

13 changes: 13 additions & 0 deletions network/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/0xPolygon/polygon-edge/network/common"
"github.com/0xPolygon/polygon-edge/network/dial"
"github.com/0xPolygon/polygon-edge/network/discovery"
"github.com/0xPolygon/polygon-edge/network/frost/proto"
"github.com/armon/go-metrics"
"github.com/libp2p/go-libp2p"
"github.com/libp2p/go-libp2p/p2p/security/noise"
Expand Down Expand Up @@ -92,6 +93,7 @@ type Server struct {
frostPeersLock sync.Mutex // lock for the peer map of topos nodes
frostPendingPeerConnections sync.Map // Map that keeps track of the frost pending status
frostConnectionCounts *ConnectionInfo
frostTopic *Topic
}

// NewServer returns a new instance of the networking server
Expand Down Expand Up @@ -285,6 +287,17 @@ func (s *Server) Start() error {
return fmt.Errorf("unable to setup frost, %w", setupErr)
}

topic, err := s.NewTopic("/frost", &proto.FrostMessage{})
if err != nil {
return err
}

if err := topic.Subscribe(s.handleFrostStatusUpdate); err != nil {
return fmt.Errorf("unable to subscribe to gossip topic, %w", err)
}

s.frostTopic = topic

// Set up the peer discovery mechanism if needed
if !s.config.NoDiscover {
// Parse the bootnode data
Expand Down
19 changes: 19 additions & 0 deletions network/server_frost.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/0xPolygon/polygon-edge/network/common"
peerEvent "github.com/0xPolygon/polygon-edge/network/event"
"github.com/0xPolygon/polygon-edge/network/frost"
"github.com/0xPolygon/polygon-edge/network/frost/proto"
"github.com/armon/go-metrics"
"github.com/libp2p/go-libp2p/core/network"
"github.com/libp2p/go-libp2p/core/peer"
Expand Down Expand Up @@ -137,3 +138,21 @@ func (s *Server) registerFrostService(frostService *frost.FrostService) {
frostStream := frost.NewFrostStream()
s.RegisterRawProtocol(common.Frost, frostStream)
}

// handleFrostStatusUpdate is a handler of gossip
func (s *Server) handleFrostStatusUpdate(obj interface{}, from peer.ID) {
frostMessage, ok := obj.(*proto.FrostMessage)
fmt.Println(">>>>>>>>>>>>>>>>>> Received frost message:", frostMessage)
if !ok {

Check failure on line 146 in network/server_frost.go

View workflow job for this annotation

GitHub Actions / golangci_lint

if statements should only be cuddled with assignments (wsl)
s.logger.Error("failed to cast gossiped frost message")
return

Check failure on line 148 in network/server_frost.go

View workflow job for this annotation

GitHub Actions / golangci_lint

return with no blank line before (nlreturn)
}

// if !s.host.Network().IsConnected(from) {
// if m.id != from.String() {
// m.logger.Debug("received status from non-connected peer, ignore", "id", from)
// }

// return
// }
}

Check failure on line 158 in network/server_frost.go

View workflow job for this annotation

GitHub Actions / golangci_lint

block should not end with a whitespace (or comment) (wsl)

0 comments on commit f3ebb94

Please sign in to comment.