Documentation
¶
Index ¶
- Variables
- func ChangeServerTLS(db *gorm.DB, address string, port uint16, tls bool) error
- func CleanupUser(db *gorm.DB, lu LocalUser) error
- func DecryptData(key, data []byte) ([]byte, error)
- func DeleteConversation(db *gorm.DB, src, dst string, address string, port uint16) error
- func DeleteLocalUser(db *gorm.DB, username string, address string, port uint16) error
- func EncryptData(key, data []byte) ([]byte, error)
- func ExternalUserExists(db *gorm.DB, username string, address string, port uint16) (bool, error)
- func GetDBLogger(logLevel uint8, logPath string) logger.Interface
- func LocalUserExists(db *gorm.DB, username string, address string, port uint16) (bool, error)
- func OpenDatabase(path string, logger logger.Interface) *gorm.DB
- func RecoverMessages(db *gorm.DB, lu LocalUser) ([][]Message, error)
- func RemoveServer(db *gorm.DB, address string, port uint16) error
- func RemoveServerByName(db *gorm.DB, name string) error
- func ServerExists(db *gorm.DB, address string, port uint16) (bool, error)
- func ServerExistsByName(db *gorm.DB, name string) (bool, error)
- func UpdateServer(db *gorm.DB, data any, column string, value any) error
- type ExternalUser
- type LocalUser
- func AddLocalUser(db *gorm.DB, username string, hashPass string, prvKeyPEM string, ...) (LocalUser, error)
- func GetAllLocalUsers(db *gorm.DB) ([]LocalUser, error)
- func GetLocalUser(db *gorm.DB, username string, address string, port uint16) (LocalUser, error)
- func GetServerLocalUsers(db *gorm.DB, address string, port uint16) ([]LocalUser, error)
- func RecoverUsers(db *gorm.DB, username string) ([]LocalUser, error)
- type Message
- func GetAllUsersMessages(db *gorm.DB, src, dst string, address string, port uint16) ([]Message, error)
- func GetUsersMessagesLimit(db *gorm.DB, src, dst string, address string, port uint16, limit time.Time) ([]Message, error)
- func StoreMessage(db *gorm.DB, src, dst string, address string, port uint16, text string, ...) (Message, error)
- type Server
- type User
Constants ¶
This section is empty.
Variables ¶
var (
ErrorInvalidObject error = fmt.Errorf("provided object is not of the correct type")
)
Functions ¶
func ChangeServerTLS ¶
Updates TLS data about a server.
func CleanupUser ¶
Cleans a user that has been recovered
func DecryptData ¶
Decrypts data using a password.
func DeleteConversation ¶
Deletes all messages between two specified users in a same server.
func DeleteLocalUser ¶
Adds a local user autoincrementally in the database and then returns it.
func EncryptData ¶
Encrypts a piece of data with a password.
func ExternalUserExists ¶
Returns true if the specified username and server defines an external user in the database.
func GetDBLogger ¶
Gets the specified log level in the client configuration file
func LocalUserExists ¶
Returns true if the specified username and server defines a local user in the database.
func OpenDatabase ¶
Opens the client database.
func RecoverMessages ¶
Tries to recover all messages asocciated to a user, separeted by conversations
func RemoveServer ¶
Deletes a server from the database given its socket.
func RemoveServerByName ¶
Deletes a server from the database given its name.
func ServerExists ¶
Returns true if the specified socket exists in the database.
func ServerExistsByName ¶
Returns true if the specified named server exists in the database.
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 ¶
Gets all the local usernames from every registered server. Fills both the user and server foreign key.
func GetLocalUser ¶
Returns the local user that is defined by the specified username and server.
func GetServerLocalUsers ¶
Gets all the local usernames from a specific server. Fils the User foreign key.
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.
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 ¶
Adds a socket pair to the database if the socket is not on it already. Also returns said server.
func GetAllServers ¶
Returns all servers in the database.
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.