Documentation ¶
Index ¶
- func CreateHandler(upgrader websocket.Upgrader, data *[]Data, blockchain *[]Block, ...) http.HandlerFunc
- func GetPeersSubscribedToTopicForPeer(peer Data, topic string) []string
- func SendDataToClients(clientsMutex *sync.Mutex, clients map[*websocket.Conn]bool, ...)
- type Block
- type Data
- type DiffData
- type PeeringConnection
- type PubsubMessageSignal
- type WebSocketMessage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateHandler ¶
func CreateHandler(upgrader websocket.Upgrader, data *[]Data, blockchain *[]Block, clientsMutex *sync.Mutex, clients map[*websocket.Conn]bool, log *ipfsLog.ZapEventLogger) http.HandlerFunc
CreateHandler returns an http.HandlerFunc that upgrades the HTTP connection to a WebSocket connection and handles incoming WebSocket connections. It takes an `upgrader` of type `websocket.Upgrader` to upgrade the connection, a slice of `Data` for storing data, a `clientsMutex` of type `*sync.Mutex` to synchronize access to the `clients` map, a `clients` map of type `map[*websocket.Conn]bool` to store connected clients, and a `log` of type `*ipfsLog.ZapEventLogger` for logging events.
The returned http.HandlerFunc upgrades the connection to a WebSocket connection and calls the `handleConnections` function to handle incoming WebSocket connections.
func SendDataToClients ¶
func SendDataToClients(clientsMutex *sync.Mutex, clients map[*websocket.Conn]bool, message WebSocketMessage, log *ipfsLog.ZapEventLogger)
SendDataToClients sends the given WebSocketMessage to all connected clients. It takes a clientsMutex to synchronize access to the clients map, a clients map that stores the connected clients, a message of type WebSocketMessage to be sent, and a log of type *ipfsLog.ZapEventLogger for logging errors. It iterates over the clients map and sends the message to each client using WriteJSON. If there is an error while sending the message, the client is closed and removed from the clients map.
Types ¶
type Data ¶
type Data struct { PeerID string `json:"peerID"` NodeType string `json:"nodeType"` ConnectedPeers []string `json:"connectedPeers"` // List of peers connected (peers ID) to this peer TopicsList []string `json:"topicsList"` KeepRelayConnectionAlive []string `json:"keepRelayConnectionAlive"` // List of peers subscribed to KeepRelayConnectionAlive which are connected to this peer BlockAnnouncement []string `json:"blockAnnouncement"` // List of peers subscribed to BlockAnnouncement which are connected to this peer AskingBlockchain []string `json:"askingBlockchain"` // List of peers subscribed to AskingBlockchain which are connected to this peer ReceiveBlockchain []string `json:"receiveBlockchain"` // List of peers subscribed to ReceiveBlockchain which are connected to this peer ClientAnnouncement []string `json:"clientAnnouncement"` // List of peers subscribed to ClientAnnouncement which are connected to this peer StorageNodeResponse []string `json:"storageNodeResponse"` // List of peers subscribed to StorageNodeResponse which are connected to this peer FullNodeAnnouncement []string `json:"fullNodeAnnouncement"` // List of peers subscribed to FullNodeAnnouncement which are connected to this peer AskMyFilesList []string `json:"askMyFilesList"` // List of peers subscribed to AskMyFilesList which are connected to this peer ReceiveMyFilesList []string `json:"receiveMyFilesList"` // List of peers subscribed to ReceiveMyFilesList which are connected to this peer }
func FindAddedNodes ¶
func FindRemovedNodes ¶
func FindUpdatedNodes ¶
type DiffData ¶
type DiffData struct { Added []Data `json:"added"` // Nodes that were added Removed []Data `json:"removed"` // Nodes that were removed Updated []Data `json:"updated"` // Nodes that were updated }
func NewDiffData ¶
type PeeringConnection ¶
func GetPeersSubscribedToTopic ¶
func GetPeersSubscribedToTopic(topic string, data []Data) ([]string, []PeeringConnection)
type PubsubMessageSignal ¶
type WebSocketMessage ¶
type WebSocketMessage struct { Type string `json:"type"` // Type specifies the type of the message. Data interface{} `json:"data"` // Data contains the payload of the message. }
WebSocketMessage represents a message sent over a WebSocket connection.