Skip to content

Commit

Permalink
fix import hub state
Browse files Browse the repository at this point in the history
  • Loading branch information
sgueissa committed Mar 17, 2024
1 parent d5b8c01 commit 2f09f1d
Showing 1 changed file with 33 additions and 33 deletions.
66 changes: 33 additions & 33 deletions be1-go/hub/hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"encoding/json"
"popstellar/channel"
"popstellar/crypto"
state2 "popstellar/hub/state"
"popstellar/hub/state"
"popstellar/inbox"
jsonrpc "popstellar/message"
"popstellar/message/answer"
Expand Down Expand Up @@ -50,6 +50,30 @@ const (

var suite = crypto.Suite

// Huber defines the methods a PoP server must implement to receive messages
// and handle clients.
type Huber interface {
// NotifyNewServer add a socket for the hub to send message to other servers
NotifyNewServer(socket.Socket)

// Start invokes the processing loop for the hub.
Start()

// Stop closes the processing loop for the hub.
Stop()

// Receiver returns a channel that may be used to process incoming messages
Receiver() chan<- socket.IncomingMessage

// OnSocketClose returns a channel which accepts socket ids on connection
// close events. This allows the hub to cleanup clients which close without
// sending an unsubscribe message
OnSocketClose() chan<- string

// SendGreetServer sends a greet server message in the socket
SendGreetServer(socket.Socket) error
}

// Hub implements the Hub interface.
type Hub struct {
clientServerAddress string
Expand All @@ -58,7 +82,7 @@ type Hub struct {
messageChan chan socket.IncomingMessage

sync.RWMutex
channelByID state2.Channels
channelByID state.Channels

closedSockets chan string

Expand All @@ -83,16 +107,16 @@ type Hub struct {
hubInbox inbox.HubInbox

// queries are used to help servers catchup to each other
queries state2.Queries
queries state.Queries

// peers stores information about the peers
peers state2.Peers
peers state.Peers

// blacklist stores the IDs of the messages that failed to be processed by the hub
// the server will not ask for them again in the heartbeat
// and will not process them if they are received again
// @TODO remove the messages from the blacklist after a certain amount of time by trying to process them again
blacklist state2.ThreadSafeSlice[string]
blacklist state.ThreadSafeSlice[string]
}

// NewHub returns a new Hub.
Expand All @@ -112,7 +136,7 @@ func NewHub(pubKeyOwner kyber.Point, clientServerAddress string, serverServerAdd
clientServerAddress: clientServerAddress,
serverServerAddress: serverServerAddress,
messageChan: make(chan socket.IncomingMessage),
channelByID: state2.NewChannelsMap(),
channelByID: state.NewChannelsMap(),
closedSockets: make(chan string),
pubKeyOwner: pubKeyOwner,
pubKeyServ: pubServ,
Expand All @@ -124,9 +148,9 @@ func NewHub(pubKeyOwner kyber.Point, clientServerAddress string, serverServerAdd
laoFac: laoFac,
serverSockets: channel.NewSockets(),
hubInbox: *inbox.NewHubInbox(rootChannel),
queries: state2.NewQueries(log),
peers: state2.NewPeers(),
blacklist: state2.NewThreadSafeSlice[string](),
queries: state.NewQueries(log),
peers: state.NewPeers(),
blacklist: state.NewThreadSafeSlice[string](),
}

return &hub, nil
Expand Down Expand Up @@ -604,27 +628,3 @@ func generateKeys() (kyber.Point, kyber.Scalar) {

return point, secret
}

// Huber defines the methods a PoP server must implement to receive messages
// and handle clients.
type Huber interface {
// NotifyNewServer add a socket for the hub to send message to other servers
NotifyNewServer(socket.Socket)

// Start invokes the processing loop for the hub.
Start()

// Stop closes the processing loop for the hub.
Stop()

// Receiver returns a channel that may be used to process incoming messages
Receiver() chan<- socket.IncomingMessage

// OnSocketClose returns a channel which accepts socket ids on connection
// close events. This allows the hub to cleanup clients which close without
// sending an unsubscribe message
OnSocketClose() chan<- string

// SendGreetServer sends a greet server message in the socket
SendGreetServer(socket.Socket) error
}

0 comments on commit 2f09f1d

Please sign in to comment.