2019-08-03 10:17:09 +00:00
|
|
|
package usermanager
|
2019-07-22 12:42:39 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
)
|
|
|
|
|
2019-08-03 10:17:09 +00:00
|
|
|
type StatusUpdate struct {
|
2019-07-22 12:42:39 +00:00
|
|
|
UID []byte
|
2019-08-03 10:17:09 +00:00
|
|
|
Active bool
|
|
|
|
NumSession int
|
2019-07-22 12:42:39 +00:00
|
|
|
|
2019-08-03 10:17:09 +00:00
|
|
|
UpUsage int64
|
|
|
|
DownUsage int64
|
|
|
|
Timestamp int64
|
2019-07-22 12:42:39 +00:00
|
|
|
}
|
|
|
|
|
2021-01-05 21:48:02 +00:00
|
|
|
type MaybeInt32 *int32
|
|
|
|
type MaybeInt64 *int64
|
|
|
|
|
2020-04-17 13:21:17 +00:00
|
|
|
type UserInfo struct {
|
|
|
|
UID []byte
|
2021-01-05 21:48:02 +00:00
|
|
|
SessionsCap MaybeInt32
|
|
|
|
UpRate MaybeInt64
|
|
|
|
DownRate MaybeInt64
|
|
|
|
UpCredit MaybeInt64
|
|
|
|
DownCredit MaybeInt64
|
|
|
|
ExpiryTime MaybeInt64
|
2020-04-17 13:21:17 +00:00
|
|
|
}
|
|
|
|
|
2021-01-05 21:48:02 +00:00
|
|
|
func JustInt32(v int32) MaybeInt32 { return &v }
|
|
|
|
|
|
|
|
func JustInt64(v int64) MaybeInt64 { return &v }
|
|
|
|
|
2019-08-03 10:17:09 +00:00
|
|
|
type StatusResponse struct {
|
2019-07-24 14:25:09 +00:00
|
|
|
UID []byte
|
2019-08-03 10:17:09 +00:00
|
|
|
Action int
|
|
|
|
Message string
|
2019-07-24 14:25:09 +00:00
|
|
|
}
|
|
|
|
|
2019-08-20 16:35:17 +00:00
|
|
|
type AuthorisationInfo struct {
|
|
|
|
NumExistingSessions int
|
|
|
|
}
|
|
|
|
|
2019-07-24 14:25:09 +00:00
|
|
|
const (
|
|
|
|
TERMINATE = iota + 1
|
|
|
|
)
|
|
|
|
|
2019-07-22 12:42:39 +00:00
|
|
|
var ErrUserNotFound = errors.New("UID does not correspond to a user")
|
|
|
|
var ErrSessionsCapReached = errors.New("Sessions cap has reached")
|
2020-12-21 15:06:46 +00:00
|
|
|
var ErrMangerIsVoid = errors.New("cannot perform operation with user manager as database path is not specified")
|
2019-07-24 14:25:09 +00:00
|
|
|
|
2019-07-22 12:42:39 +00:00
|
|
|
var ErrNoUpCredit = errors.New("No upload credit left")
|
|
|
|
var ErrNoDownCredit = errors.New("No download credit left")
|
|
|
|
var ErrUserExpired = errors.New("User has expired")
|
|
|
|
|
|
|
|
type UserManager interface {
|
2019-08-03 10:17:09 +00:00
|
|
|
AuthenticateUser([]byte) (int64, int64, error)
|
2019-08-20 16:35:17 +00:00
|
|
|
AuthoriseNewSession([]byte, AuthorisationInfo) error
|
2019-08-03 10:17:09 +00:00
|
|
|
UploadStatus([]StatusUpdate) ([]StatusResponse, error)
|
2020-04-17 13:21:17 +00:00
|
|
|
ListAllUsers() ([]UserInfo, error)
|
|
|
|
GetUserInfo(UID []byte) (UserInfo, error)
|
|
|
|
WriteUserInfo(UserInfo) error
|
|
|
|
DeleteUser(UID []byte) error
|
2019-07-22 12:42:39 +00:00
|
|
|
}
|