peerutils

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const BUF_SIZE = 1024
View Source
const Blue = "\033[34m"
View Source
const ColorReset = "\033[0m"
View Source
const Cyan = "\033[36m"
View Source
const Gray = "\033[37m"
View Source
const Green = "\033[32m"
View Source
const (
	ID_SIZE = 512
)
View Source
const MAX_MSG_COUNT = 50
View Source
const MESSAGE_DISCONNECT byte = 0x3
View Source
const MESSAGE_INIT byte = 0x1
View Source
const MESSAGE_TXT byte = 0x2
View Source
const Magenta = "\033[35m"
View Source
const RES_ERR byte = 0x1
View Source
const RES_OK byte = 0x0

message codes wil be defined here

View Source
const Red = "\033[31m"
View Source
const White = "\033[97m"
View Source
const Yellow = "\033[33m"

Variables

This section is empty.

Functions

func GenId

func GenId(prvKey *rsa.PrivateKey) (string, error)

given a user's private key, generates their id, in the form of a Base64-encoded signature of a constant

func RecvAll

func RecvAll(conn net.Conn) (int, []byte, error)

recieves data of unknown size from Conn object

func ValidateId

func ValidateId(id string, pubKey *rsa.PublicKey) bool

verifies a peer's ID given their public key

Types

type Chatroom

type Chatroom struct {
	Tunnel   Tunnel
	Messages []Message
	Active   bool
}

func (*Chatroom) AwaitMessage

func (c *Chatroom) AwaitMessage() error

awaits an incoming message, and handles it according to its code

func (Chatroom) DisplayMessages

func (c Chatroom) DisplayMessages()

displays all of the Messages currently in the archive

func (*Chatroom) HandleCommand

func (c *Chatroom) HandleCommand(command string, args []string) string

handles a chat command, and returns the string to be output to the terminal after running

func (*Chatroom) SendMessage

func (c *Chatroom) SendMessage(msg *string) error

sends a string message to the peer

type Message

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

func NewMessage

func NewMessage(content string, usr *User) *Message

constructs a new message, making a note of the current timestamp

func (Message) Display

func (m Message) Display()

type Tunnel

type Tunnel struct {
	PeerPubKey rsa.PublicKey

	Incoming net.Conn
	Outgoing net.Conn
	Peer     User
	User     User
	// contains filtered or unexported fields
}

func AwaitPeer

func AwaitPeer(pubKey rsa.PublicKey, prvKey rsa.PrivateKey, reciever User) (*Tunnel, error)

func ConnectPeer

func ConnectPeer(addr string, pubKey rsa.PublicKey, prvKey rsa.PrivateKey, initiator User) (*Tunnel, error)

attempts to connect to a peer, returning a tunnel if the peer can be reached

func (Tunnel) AwaitMessage

func (t Tunnel) AwaitMessage() ([]byte, error)

func (Tunnel) SendMessage

func (t Tunnel) SendMessage(message []byte) error

encrypts and sends the provided message through this Tunnel

func (Tunnel) Shutdown

func (t Tunnel) Shutdown() error

quits the connection and sends a message to the peer indicating such

type User

type User struct {
	Name  string
	Color string
	Id    string
}

Jump to

Keyboard shortcuts

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