sync

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var PublicKeyLocation string

Functions

func AddKey

func AddKey(userID int64, key string)

AddKey adds the given key to the key file of the given user

func Authenticate

func Authenticate(r *http.Request, body data.SyncRequest) bool

Authenticate returns true iff the JWT specified in the HTTP requests' Bearer token was signed by the correct user. If any step of the authentication process fails or there is no matching public key, Authenticate returns false

func AuthenticateWithKeySet

func AuthenticateWithKeySet(r *http.Request, userID int64, keySet jwk.Set) bool

AuthenticateWithKeySet returns true iff the JWT in the Bearer token can be validated in verified with a key in the given key set

func GetFreeUserID

func GetFreeUserID() int64

GetFreeUserID returns the smallest valid unused user id

func GetKeySet

func GetKeySet(userId int64) (jwk.Set, error)

GetKeySet returns the key set of user with a given userId. Returns an error if the keys file of that user was not found or could not be parsed.

func GetUsedUserIDs

func GetUsedUserIDs() map[int64]bool

GetUsedUserIDs returns a map containing every user id with an existing file [user id]_keys in PublicKeyLocation directory

func HandleSyncRequest

func HandleSyncRequest(w http.ResponseWriter, req *http.Request, noAuth bool)

HandleSyncRequest receives sync requests and starts the sync process with the received data.

func ReadKey

func ReadKey(path string) string

ReadKey reads the key from a file

func SolveConflict

func SolveConflict(userId int64, store storage.Storage) (bool, error)

SolveConflict merges overlapping intervals of given user. It then updates userId's state in store accordingly SolveConflict returns true iff a conflict was detected

func Sync

func Sync(syncRequest data.SyncRequest, store storage.Storage) ([]data.Interval, bool, error)

Sync updates the stored state in passed storage.Storage for the user issuing the sync request. If something fails it tries to restore the state prior to the syncRequest. This is not always possible though. The error message denotes whether restoring state was successful. Later atomicity should be guaranteed by storage. Iff no errors occur Sync returns the synced interval data of the user issuing the sync request.

func UniteTagsAndAnnotation

func UniteTagsAndAnnotation(a data.Interval, b data.Interval) ([]string, string)

UniteTagsAndAnnotation computes the new tags and annotation for overlapping intervals and returns tags, annotation. Case 1: Iff only one interval has an Annotation, we use this annotation. Case 2: Iff no interval has an annotation, we use "" as annotation. Case 3: Iff both intervals have different annotation, we use "" as annotation, and add both annotation to tags. Case 4: Iff both intervals have the same annotation, we just use that annotation As tags we return the alphabetically sorted union of both intervals' tags (and both annotations in Case 3) without duplicates.

Types

type ErrorResponseBody

type ErrorResponseBody struct {
	Message string `json:"message"`
	Details string `json:"details"`
}

An ErrorResponseBody represents a JSON message that is sent to the client when an error occurs

func (ErrorResponseBody) ToString

func (e ErrorResponseBody) ToString() string

Returns a string representation of this error reponse which will be sent to the client

Jump to

Keyboard shortcuts

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