node

package
v0.0.0-...-5156b21 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 17, 2021 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Node

type Node interface {
	ID() peer.ID

	Start(ctx context.Context, port uint16) error
	Bootstrap(ctx context.Context, nodeAddrs []multiaddr.Multiaddr) error

	SendMessage(ctx context.Context, roomName string, msg string) error

	JoinRoom(roomName string, nickname string) error
	GetRoomParticipants(roomName string) ([]participantsEntry, error)

	SetNickname(roomName string, nickname string) error
	GetNickname(roomName string, peerID peer.ID) (string, error)

	SubscribeToEvents() (events.Subscriber, error)

	Shutdown() error
}

func NewNode

func NewNode(logger *zap.Logger, boostrapOnly bool, storeIdentity bool) Node

type Room

type Room struct {
	// contains filtered or unexported fields
}

Room holds room event and pubsub data.

type RoomManager

type RoomManager struct {
	// contains filtered or unexported fields
}

RoomManager manages rooms through pubsub subscription and implements room operations.

func NewRoomManager

func NewRoomManager(logger *zap.Logger, node Node, kadDHT *dht.IpfsDHT, ps *pubsub.PubSub) (*RoomManager, events.Subscriber)

NewRoomManager creates a new room manager.

func (*RoomManager) GetNickname

func (r *RoomManager) GetNickname(
	roomName string,
	peerID peer.ID,
) (string, bool, error)

GetNickname tries to find the nickname of a peer in the DHT.

func (*RoomManager) GetRoomParticipants

func (r *RoomManager) GetRoomParticipants(roomName string) ([]participantsEntry, error)

GetRoomParticipants returns the list of peers in a room.

func (*RoomManager) HasJoined

func (r *RoomManager) HasJoined(roomName string) bool

HasJoined returns whether the manager has joined a given room.

func (*RoomManager) JoinAndSubscribe

func (r *RoomManager) JoinAndSubscribe(roomName string, nickname string) (bool, error)

JoinAndSubscribe joins and subscribes to a room.

func (*RoomManager) SendChatMessage

func (r *RoomManager) SendChatMessage(ctx context.Context, roomName string, msg entities.Message) error

SendChatMessage sends a chat message to a given room. Fails if it has not yet joined the given room.

func (*RoomManager) SetNickname

func (r *RoomManager) SetNickname(roomName string, nickname string) error

SetNickname sets the node's nickname in a given room.

func (*RoomManager) TopicName

func (r *RoomManager) TopicName(roomName string) string

TopicName builds a string containing the name of the pubsub topic for a given room name.

type RoomMessageIn

type RoomMessageIn struct {
	Type    RoomMessageType `json:"type"`
	Payload json.RawMessage `json:"payload,omitempty"`
}

RoomMessageIn holds data to be received from a topic.

The Payload field is lazily unmarshalled because it depends on the type of message published.

type RoomMessageOut

type RoomMessageOut struct {
	Type    RoomMessageType `json:"type"`
	Payload interface{}     `json:"payload,omitempty"`
}

RoomMessageOut holds data to be published in a topic.

type RoomMessageType

type RoomMessageType string

RoomMessageType enumerates the possible types of pubsub room messages.

const (
	// RoomMessageTypeChatMessage is published when a new chat message is sent from the node.
	RoomMessageTypeChatMessage RoomMessageType = "room.message"

	// RoomMessageTypeAdvertise is published to indicate a node is still connected to a room.
	RoomMessageTypeAdvertise RoomMessageType = "room.advertise"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL