db

package
v0.0.0-...-f701b90 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorInvalidObject error = fmt.Errorf("provided object is not of the correct type")
)

Functions

func ChangeServerTLS

func ChangeServerTLS(db *gorm.DB, address string, port uint16, tls bool) error

Updates TLS data about a server.

func CleanupUser

func CleanupUser(db *gorm.DB, lu LocalUser) error

Cleans a user that has been recovered

func DecryptData

func DecryptData(key, data []byte) ([]byte, error)

Decrypts data using a password.

func DeleteConversation

func DeleteConversation(db *gorm.DB, src, dst string, address string, port uint16) error

Deletes all messages between two specified users in a same server.

func DeleteLocalUser

func DeleteLocalUser(db *gorm.DB, username string, address string, port uint16) error

Adds a local user autoincrementally in the database and then returns it.

func EncryptData

func EncryptData(key, data []byte) ([]byte, error)

Encrypts a piece of data with a password.

func ExternalUserExists

func ExternalUserExists(db *gorm.DB, username string, address string, port uint16) (bool, error)

Returns true if the specified username and server defines an external user in the database.

func GetDBLogger

func GetDBLogger(logLevel uint8, logPath string) logger.Interface

Gets the specified log level in the client configuration file

func LocalUserExists

func LocalUserExists(db *gorm.DB, username string, address string, port uint16) (bool, error)

Returns true if the specified username and server defines a local user in the database.

func OpenDatabase

func OpenDatabase(path string, logger logger.Interface) *gorm.DB

Opens the client database.

func RecoverMessages

func RecoverMessages(db *gorm.DB, lu LocalUser) ([][]Message, error)

Tries to recover all messages asocciated to a user, separeted by conversations

func RemoveServer

func RemoveServer(db *gorm.DB, address string, port uint16) error

Deletes a server from the database given its socket.

func RemoveServerByName

func RemoveServerByName(db *gorm.DB, name string) error

Deletes a server from the database given its name.

func ServerExists

func ServerExists(db *gorm.DB, address string, port uint16) (bool, error)

Returns true if the specified socket exists in the database.

func ServerExistsByName

func ServerExistsByName(db *gorm.DB, name string) (bool, error)

Returns true if the specified named server exists in the database.

func UpdateServer

func UpdateServer(db *gorm.DB, data any, column string, value any) error

Update information about a server using its internal ID. Values provided as "any" must be a pointer

Types

type ExternalUser

type ExternalUser struct {
	UserID uint   `gorm:"primaryKey;not null"`
	PubKey string `gorm:"not null"`

	User User `gorm:"foreignKey:UserID;OnDelete:CASCADE"`
}

User extension dedicated to REQ'd users. Only their public key is needed to encrypt messages to them.

func AddExternalUser

func AddExternalUser(db *gorm.DB, username string, pubKeyPEM string, address string, port uint16) (ExternalUser, error)

Adds a local user autoincrementally in the database and then returns it.

func GetExternalUser

func GetExternalUser(db *gorm.DB, username string, address string, port uint16) (ExternalUser, error)

Returns the external user that is defined by the specified username and server.

func GetRequestedUsers

func GetRequestedUsers(db *gorm.DB) ([]ExternalUser, error)

Gets all the external users found in the database.

type LocalUser

type LocalUser struct {
	UserID   uint   `gorm:"primaryKey;not null;autoIncrement:false"`
	Password string `gorm:"not null"`
	PrvKey   string

	User User `gorm:"foreignKey:UserID;OnDelete:CASCADE"`
}

User extension dedicated to locally created users. The passwords should be hashed and the private keys need to be stored in PEM format.

func AddLocalUser

func AddLocalUser(db *gorm.DB, username string, hashPass string, prvKeyPEM string, address string, port uint16) (LocalUser, error)

Adds a local user autoincrementally in the database and then returns it.

func GetAllLocalUsers

func GetAllLocalUsers(db *gorm.DB) ([]LocalUser, error)

Gets all the local usernames from every registered server. Fills both the user and server foreign key.

func GetLocalUser

func GetLocalUser(db *gorm.DB, username string, address string, port uint16) (LocalUser, error)

Returns the local user that is defined by the specified username and server.

func GetServerLocalUsers

func GetServerLocalUsers(db *gorm.DB, address string, port uint16) ([]LocalUser, error)

Gets all the local usernames from a specific server. Fils the User foreign key.

func RecoverUsers

func RecoverUsers(db *gorm.DB, username string) ([]LocalUser, error)

Tries to recover all local users not belonging to any server given a username

type Message

type Message struct {
	MessageID     uint `gorm:"primaryKey;autoincrement;not null"`
	SourceID      uint
	DestinationID uint
	Stamp         time.Time
	Text          string

	SourceUser      User `gorm:"foreignKey:SourceID;references:UserID;OnDelete:RESTRICT"`
	DestinationUser User `gorm:"foreignKey:DestinationID;references:UserID;OnDelete:RESTRICT"`
}

Holds message data.

func GetAllUsersMessages

func GetAllUsersMessages(db *gorm.DB, src, dst string, address string, port uint16) ([]Message, error)

Returns a slice with all messages between two users, filling foreign keys.

func GetUsersMessagesLimit

func GetUsersMessagesLimit(db *gorm.DB, src, dst string, address string, port uint16, limit time.Time) ([]Message, error)

Returns a slice with every message between two users until a certain point in time.

func StoreMessage

func StoreMessage(db *gorm.DB, src, dst string, address string, port uint16, text string, stamp time.Time) (Message, error)

Adds a message to the database and returns it.

type Server

type Server struct {
	Address  string `gorm:"primaryKey;autoIncrement:false;not null"`
	Port     uint16 `gorm:"primaryKey;autoIncrement:false;not null"`
	TLS      bool   `gorm:"not null"`
	ServerID uint   `gorm:"autoIncrement:false;not null"`
	Name     string `gorm:"unique;not null"`
}

Server indentifier that allows a multi-server platform.

func AddServer

func AddServer(db *gorm.DB, address string, port uint16, name string, tls bool) (Server, error)

Adds a socket pair to the database if the socket is not on it already. Also returns said server.

func GetAllServers

func GetAllServers(db *gorm.DB) ([]Server, error)

Returns all servers in the database.

func GetServer

func GetServer(db *gorm.DB, address string, port uint16) (Server, error)

Returns the server with the specified socket.

func GetServerByName

func GetServerByName(db *gorm.DB, name string) (Server, error)

Returns the server with the specified name.

type User

type User struct {
	UserID   uint   `gorm:"autoIncrement:false;not null"`
	ServerID uint   `gorm:"primaryKey;autoIncrement:false;not null"`
	Username string `gorm:"primaryKey;not null"`

	Server Server `gorm:"foreignKey:ServerID;references:ServerID;constraint:OnDelete:CASCADE"`
}

Generic user table that defines the columns every user shares.

func GetUser

func GetUser(db *gorm.DB, username string, address string, port uint16) (User, error)

Returns the user that is defined by the username and server.

Jump to

Keyboard shortcuts

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