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
|
|
|
}
|
|
|
|
|
2020-04-17 13:21:17 +00:00
|
|
|
type UserInfo struct {
|
|
|
|
UID []byte
|
2020-04-23 22:45:12 +00:00
|
|
|
SessionsCap int32
|
2020-04-17 13:21:17 +00:00
|
|
|
UpRate int64
|
|
|
|
DownRate int64
|
|
|
|
UpCredit int64
|
|
|
|
DownCredit int64
|
|
|
|
ExpiryTime int64
|
|
|
|
}
|
|
|
|
|
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")
|
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
|
|
|
}
|