peerutils

package
v0.1.2 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	DEFAULT_ROUNDS = 256
	SALT_SIZE      = 16
	MAX_MSG_COUNT  = 50
)
View Source
const (
	RES_OK             byte = 0x0
	RES_ERR            byte = 0x1
	MESSAGE_INIT       byte = 0x1
	MESSAGE_TXT        byte = 0x2
	MESSAGE_DISCONNECT byte = 0x3
	CHAT_ARCHIVE       byte = 0x4
)

message codes wil be defined here

View Source
const BUF_SIZE = 1024
View Source
const Blue = "\033[34m"
View Source
const Bold = "\033[1m"
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 Italic = "\033[3m"
View Source
const Magenta = "\033[35m"
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 DecryptArchive added in v0.1.1

func DecryptArchive(fileName string, password []byte) (string, error)

returns a string of a decrypted chat archive

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) ArchiveChat added in v0.1.1

func (c Chatroom) ArchiveChat(password []byte, path string, rounds int) error

archives a chat and saves it to a file in a given path

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(file io.Writer)

displays all of the Messages currently in the archive

func (*Chatroom) HandleCommand

func (c *Chatroom) HandleCommand(command string, args []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(stream io.Writer)

displays a message to an output stream, usually this will be stdout, but this needs to be adjustable for archival purposes

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