gochat

package
v0.0.0-...-651cc80 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2017 License: GPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	REGISTER     = COMMAND("Register")
	AUTHENTICATE = COMMAND("Authenticate")
	TOKEN        = COMMAND("Token")
	LIST_ROOMS   = COMMAND("List Rooms")
	JOIN_ROOM    = COMMAND("Join Room")
	LEAVE_ROOM   = COMMAND("Leave Room")
	CREATE_ROOM  = COMMAND("Create Room")
	CLOSE_ROOM   = COMMAND("Close Room")
	SEND_MSG     = COMMAND("Send Message")
	RECV_MSG     = COMMAND("Receive Message")
	POP_MSGS     = COMMAND("Populate Messages")
)
View Source
const (
	SUCCESS = STATUS("Request was successfull")
	FAILURE = STATUS("Request failed")
)
View Source
const (
	CREATE_ROOM_SQL   = "INSERT INTO rooms (name, capacity, closed) VALUES (?, ?, ?)"
	GET_ALL_ROOMS_SQL = "SELECT * FROM rooms WHERE closed=?"
	DELETE_ROOM_SQL   = "DELETE FROM rooms WHERE name=?"
	GET_ROOM_SQL      = "SELECT * FROM rooms WHERE name=?"
	ROOM_SCHEMA       = `` /* 136-byte string literal not displayed */

)
View Source
const (
	CREATE_MESSAGE_SQL       = "INSERT INTO messages (user_id, room_id, message, epoch_timestamp) VALUES (?, ?, ?, ?)"
	GET_LATEST_ROOM_MESSAGES = `` /* 219-byte string literal not displayed */

	MESSAGE_SCHEMA = `` /* 158-byte string literal not displayed */

)
View Source
const (
	TOKEN_LENGTH  = 12
	TOKEN_LETTERS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
)
View Source
const (
	CREATE_USER_SQL     = "INSERT INTO users (username, salt, password_sha256, Deleted) VALUES (?, ?, ?, ?)"
	UPDATE_PASSWORD_SQL = "UPDATE users SET salt=?, password_sha256=? WHERE username=?"
	DELETE_USER_SQL     = "UPDATE users SET deleted=true WHERE username=?"
	GET_USER_SQL        = "SELECT * FROM users WHERE username=? AND deleted=?"
	USER_SCHEMA         = `` /* 158-byte string literal not displayed */

)
View Source
const (
	SALT_BYTES = 64
)

Variables

This section is empty.

Functions

func GetStartupChoice

func GetStartupChoice(choices []string) int

func RegisterStructs

func RegisterStructs()

func SendRemoteCommand

func SendRemoteCommand(encoder *gob.Encoder, message Message) error

Types

type AuthenticateMessage

type AuthenticateMessage struct {
	Username     string
	PasswordHash string
}

type COMMAND

type COMMAND string

type ChatClient

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

func NewChatClient

func NewChatClient(logger *log.Entry) (*ChatClient, error)

func (*ChatClient) Authenticate

func (client *ChatClient) Authenticate(username string, password string) error

func (*ChatClient) BuildCloseRoomMessage

func (client *ChatClient) BuildCloseRoomMessage(room string) (Message, error)

func (*ChatClient) BuildCreateRoomMessage

func (client *ChatClient) BuildCreateRoomMessage(room string, capacity int) (Message, error)

func (*ChatClient) BuildJoinRoomMessage

func (client *ChatClient) BuildJoinRoomMessage(room string) (Message, error)

func (*ChatClient) BuildLeaveRoomMessage

func (client *ChatClient) BuildLeaveRoomMessage(room string) (Message, error)

func (*ChatClient) BuildListRoomsMessage

func (client *ChatClient) BuildListRoomsMessage() (Message, error)

func (*ChatClient) BuildPopulateMessage

func (client *ChatClient) BuildPopulateMessage(roomName string, timeSince time.Time) (Message, error)

func (*ChatClient) BuildSendMessageMessage

func (client *ChatClient) BuildSendMessageMessage(content string, room string) (Message, error)

func (*ChatClient) Connect

func (client *ChatClient) Connect(connection_string string) error

func (*ChatClient) DisplayPopulateMessages

func (client *ChatClient) DisplayPopulateMessages(message PopulateMessages)

func (*ChatClient) DisplayRoomListingMessage

func (client *ChatClient) DisplayRoomListingMessage(message ListRoomsMessage)

func (*ChatClient) DisplayTextMessage

func (client *ChatClient) DisplayTextMessage(message TextMessage)

func (*ChatClient) EventLoop

func (client *ChatClient) EventLoop(server_messages <-chan Message, client_messages <-chan Message, exit <-chan int)

func (*ChatClient) HandleServerMessage

func (client *ChatClient) HandleServerMessage(message Message) error

func (*ChatClient) ListenToServer

func (client *ChatClient) ListenToServer(notify chan<- Message, exit <-chan int, auth chan<- bool) error

func (*ChatClient) ListenToUser

func (client *ChatClient) ListenToUser(message_channel chan<- Message) error

func (*ChatClient) Register

func (client *ChatClient) Register(username string, password string) error

type ChatServer

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

func NewChatServer

func NewChatServer(logger *log.Entry, config ServerConfig) (*ChatServer, error)

func (*ChatServer) HandleIncomingConnection

func (server *ChatServer) HandleIncomingConnection(connection net.Conn)

func (*ChatServer) HandleMessage

func (server *ChatServer) HandleMessage(message Message, encoder *gob.Encoder) (Message, error)

func (ChatServer) Listen

func (server ChatServer) Listen(connection_string string) error

type CloseRoomMessage

type CloseRoomMessage struct {
	Room  string
	Token string
}

type CreateRoomMessage

type CreateRoomMessage struct {
	Room     string
	Capacity int
	Token    string
}

type DatabaseConfig

type DatabaseConfig struct {
	Product  string `yaml:"product"`
	Host     string `yaml:"host"`
	Port     string `yaml:"port"`
	Database string `yaml:"database"`
	User     string `yaml:"user"`
	Password string `yaml:"password"`
}

type JoinRoomMessage

type JoinRoomMessage struct {
	Username    string
	Room        string
	IsSuperUser bool
	Token       string
	Status      STATUS
	Message     TextMessage
}

type LeaveRoomMessage

type LeaveRoomMessage struct {
	Username string
	Room     string
	Token    string
	Status   STATUS
	Message  TextMessage
}

type ListRoomsMessage

type ListRoomsMessage struct {
	Rooms []string
}

type Message

type Message struct {
	Command  COMMAND
	Contents interface{}
}

func BuildMessage

func BuildMessage(message_type COMMAND, contents interface{}) Message

type PopulateMessages

type PopulateMessages struct {
	Room      string
	Messages  []TextMessage
	TimeSince int
	Limit     int
	Token     string
}

type RecvTextMessage

type RecvTextMessage struct {
	Message TextMessage
}

type RegisterMessage

type RegisterMessage struct {
	Username     string
	PasswordHash string
}

type Room

type Room struct {
	Id       int    `db:"id"`
	Name     string `db:"name"`
	Capacity int    `db:"capacity"`
	Closed   bool   `db:"closed"`
}

type RoomManager

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

func NewRoomManager

func NewRoomManager(storage *StorageManager, logger *log.Entry) (*RoomManager, error)

func (*RoomManager) CloseRoom

func (manager *RoomManager) CloseRoom(name string) (*ServerRoom, error)

func (*RoomManager) CreateRoom

func (manager *RoomManager) CreateRoom(name string, capacity int) (*ServerRoom, error)

func (*RoomManager) GetRoom

func (manager *RoomManager) GetRoom(name string) (*ServerRoom, error)

func (*RoomManager) GetRoomNames

func (manager *RoomManager) GetRoomNames() []string

func (*RoomManager) LoadRooms

func (manager *RoomManager) LoadRooms() error

type RoomMessage

type RoomMessage struct {
	Username  string `db:"username"`
	Message   string `db:"message"`
	Timestamp int64  `db:"epoch_timestamp"`
}

type RoomMessageManager

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

func NewRoomMessageManager

func NewRoomMessageManager(storageManager *StorageManager, roomManager *RoomManager, userManager *UserManager, logger *log.Entry) (*RoomMessageManager, error)

func (*RoomMessageManager) GetRoomMessagesSince

func (manager *RoomMessageManager) GetRoomMessagesSince(room *ServerRoom, timeSince time.Time, limit int) ([]TextMessage, error)

func (*RoomMessageManager) PersistRoomMessage

func (manager *RoomMessageManager) PersistRoomMessage(user *ServerUser, room *ServerRoom, message string) error

type STATUS

type STATUS string

type SendTextMessage

type SendTextMessage struct {
	Token   string
	Message TextMessage
}

type ServerConfig

type ServerConfig struct {
	Database DatabaseConfig `yaml:"database"`
}

func LoadServerConfigurationFile

func LoadServerConfigurationFile(filename string) (ServerConfig, error)

type ServerRoom

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

func (*ServerRoom) AddUser

func (room *ServerRoom) AddUser(user *ServerUser) error

func (*ServerRoom) RemoveUser

func (room *ServerRoom) RemoveUser(user *ServerUser) error

func (*ServerRoom) String

func (room *ServerRoom) String() string

type ServerRoomMessage

type ServerRoomMessage struct {
	RoomMessage *RoomMessage
	Room        *ServerRoom
	User        *ServerUser
	Timestamp   time.Time
}

func (*ServerRoomMessage) String

func (message *ServerRoomMessage) String() string

type ServerUser

type ServerUser struct {
	User *User
	// contains filtered or unexported fields
}

func (*ServerUser) GetToken

func (user *ServerUser) GetToken() string

func (*ServerUser) String

func (user *ServerUser) String() string

type StorageManager

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

func NewStorageManager

func NewStorageManager(config DatabaseConfig, logger *log.Entry) (*StorageManager, error)

func (*StorageManager) CheckExecOutcome

func (manager *StorageManager) CheckExecOutcome(result driver.Result, err error, affectedCheck func(int64) bool) error

Convenience wrapper around the DB's Exec call result, it returns any errors Exec encounters It also has an affectedCheck anon function that ensure the correct number of rows is affected

func (*StorageManager) CloseStorage

func (manager *StorageManager) CloseStorage() error

func (*StorageManager) ExecAtLeastOneRow

func (manager *StorageManager) ExecAtLeastOneRow(result driver.Result, err error) error

func (*StorageManager) ExecOneRow

func (manager *StorageManager) ExecOneRow(result driver.Result, err error) error

func (*StorageManager) ExecZeroOrMoreRows

func (manager *StorageManager) ExecZeroOrMoreRows(result driver.Result, err error) error

type TextMessage

type TextMessage struct {
	Username string
	Room     string
	Text     string
	Time     time.Time
}

type TokenMessage

type TokenMessage struct {
	Username string
	Token    string
	Message  string
}

type User

type User struct {
	Id              int    `db:"id"`
	Username        string `db:"username"`
	Salt            string `db:"salt"`
	Password_sha256 string `db:"password_sha256"`
	Deleted         bool   `db:"deleted"`
}

type UserManager

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

func NewUserManager

func NewUserManager(storage *StorageManager, logger *log.Entry) (*UserManager, error)

func (*UserManager) AuthenticateUser

func (manager *UserManager) AuthenticateUser(username string, password_sha256 string) (*ServerUser, error)

func (*UserManager) CreateUser

func (manager *UserManager) CreateUser(username string, password string) error

func (*UserManager) DeleteUser

func (manager *UserManager) DeleteUser(username string) error

func (*UserManager) GetUser

func (manager *UserManager) GetUser(username string) (*ServerUser, error)

func (*UserManager) TokenIsValid

func (manager *UserManager) TokenIsValid(token string) (bool, error)

func (*UserManager) UpdatePassword

func (manager *UserManager) UpdatePassword(username string, password string) error

Jump to

Keyboard shortcuts

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