chat

package
v0.0.0-...-198cc34 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2021 License: Apache-2.0 Imports: 39 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewNetwork

func NewNetwork(cr *ChatRoom) network.Network

Types

type ChatRoom

type ChatRoom struct {
	// Represents the P2P Host for the ChatRoom
	Host *P2P

	InboundChat          chan chatmessage
	OutboundChat         chan chatmessage
	InboundProtocolStart chan chatmessage
	InboundProtocol      chan *protocol.Message
	OutboundProtocol     chan *protocol.Message
	Logs                 chan chatlog
	// contains filtered or unexported fields
}

A structure that represents a PubSub Chat Room

func JoinChatRoom

func JoinChatRoom(p2phost *P2P, cfg *config.AppConfig) (*ChatRoom, error)

A constructor function that generates and returns a new ChatRoom for a given P2PHost, username and roomname

func (*ChatRoom) AddParticipant

func (cr *ChatRoom) AddParticipant(peerid peer.ID, u user.User)

func (*ChatRoom) Exit

func (cr *ChatRoom) Exit()

func (*ChatRoom) ParticipantList

func (cr *ChatRoom) ParticipantList() []*participant

func (*ChatRoom) PubLoop

func (cr *ChatRoom) PubLoop()

A method of ChatRoom that publishes a chatmessage to the PubSub topic until the pubsub context closes

func (*ChatRoom) SubLoop

func (cr *ChatRoom) SubLoop()

A method of ChatRoom that continously reads from the subscription until either the subscription or pubsub context closes. The recieved message is parsed sent into the inbound channel

type P2P

type P2P struct {
	Ctx          context.Context
	Me           user.Me
	Host         core.Host
	KadDHT       *dht.IpfsDHT
	Discovery    *discovery.RoutingDiscovery
	PubSub       *pubsub.PubSub
	ChatroomName string
}

A structure that represents a P2P Host

func NewP2P

func NewP2P(me user.Me, chatroomname string, bootstrapaddrs []string, listenaddrs []string) *P2P

A constructor function that generates and returns a P2P object.

Constructs a libp2p host with TLS encrypted secure transportation that works over a TCP transport connection using a Yamux Stream Multiplexer and uses UPnP for the NAT traversal.

A Kademlia DHT is then bootstrapped on this host using the specified peers and a Peer Discovery service is created from this Kademlia DHT. The PubSub handler is then created on the host using the peer discovery service created prior.

func (*P2P) AdvertiseConnect

func (p2p *P2P) AdvertiseConnect()

A method of P2P to connect to service peers. This method uses the Advertise() functionality of the Peer Discovery Service to advertise the service and then discovers all peers advertising the same. The peer discovery is handled by a go-routine that will read from a channel of peer address information until the peer channel closes

func (*P2P) AnnounceConnect

func (p2p *P2P) AnnounceConnect()

A method of P2P to connect to service peers. This method uses the Provide() functionality of the Kademlia DHT directly to announce the ability to provide the service and then discovers all peers that provide the same. The peer discovery is handled by a go-routine that will read from a channel of peer address information until the peer channel closes

type TermApp

type TermApp struct {
	TerminalApp *tview.Application
	// contains filtered or unexported fields
}

A structure that represents the tview application

func NewTerminalApp

func NewTerminalApp(blockchain string, roomname string, nick string, cmdchan chan UICommand, msgchan chan string) *TermApp

Create a new tview application

type UI

type UI struct {
	*ChatRoom
	*TermApp

	MsgInputs chan string
	CmdInputs chan UICommand
	// contains filtered or unexported fields
}

A structure that represents the ChatRoom UI

func NewUI

func NewUI(cr *ChatRoom, net network.Network) *UI

Create a new Chatroom UI

func (*UI) Close

func (ui *UI) Close()

func (*UI) Run

func (ui *UI) Run() error

type UICommand

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

A structure that represents a UI command (i.e. /somecommand)

Jump to

Keyboard shortcuts

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