mychat

package
v0.0.0-...-550c479 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2022 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const ChatRoomBufSize = 128

ChatRoomBufSize is the number of incoming messages to buffer for each topic.

View Source
const RSABits = 2048

Variables

This section is empty.

Functions

func CreateHost

func CreateHost(config Config) (host.Host, error)

func GenerateRandString

func GenerateRandString(n int) string

func StringsToAddrs

func StringsToAddrs(addrStrings []string) (maddrs []maddr.Multiaddr, err error)

Types

type ChatMessage

type ChatMessage struct {
	Message          string
	SenderID         string
	SenderNick       string
	ReceiverNickName string
}

ChatMessage gets converted to/from JSON and sent in the body of pubsub messages.

type ChatRoom

type ChatRoom struct {
	// Messages is a channel of messages received from other peers in the chat room
	Messages chan *ChatMessage
	// contains filtered or unexported fields
}

ChatRoom represents a subscription to a single PubSub topic. Messages can be published to the topic with ChatRoom.Publish, and received messages are pushed to the Messages channel.

func JoinChatRoom

func JoinChatRoom(ctx context.Context, hostP2P host.Host, config Config, logger *log.Logger) (*ChatRoom, error)

JoinChatRoom tries to subscribe to the PubSub topic for the room name, returning a ChatRoom on success.

func (*ChatRoom) ListPeers

func (cr *ChatRoom) ListPeers() []peer.ID

func (*ChatRoom) Publish

func (cr *ChatRoom) Publish(message string, to string) error

Publish sends a message to the pubsub topic.

type Config

type Config struct {
	RendezvousString  string
	BootstrapPeers    addrList
	ListenAddresses   addrList
	NickName          string
	RoomName          string
	FindPeersTimeSecs int
	Port              int
	PrivateKey        string
	OutputPrivateKey  bool
	Help              bool
}

func ParseFlags

func ParseFlags() *Config

func (Config) BoostrapPeersMultiAdresses

func (config Config) BoostrapPeersMultiAdresses() []maddr.Multiaddr

func (Config) FindPeersTimeSecsDuration

func (config Config) FindPeersTimeSecsDuration() time.Duration

func (Config) ListenMultiAdresses

func (config Config) ListenMultiAdresses() []maddr.Multiaddr

type MyDiscovery

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

func NewMyDicovery

func NewMyDicovery(ctx context.Context, hostP2P host.Host, config Config, logger *log.Logger) (*MyDiscovery, error)

func (MyDiscovery) AdvertiseAndFindPeers

func (discovery MyDiscovery) AdvertiseAndFindPeers(config Config)

Jump to

Keyboard shortcuts

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