Documentation ¶
Index ¶
- Constants
- Variables
- func Contains(s []string, value string) bool
- func ContentHash(path string) (string, error)
- func Difference(start, target map[string]bool) (created, modified, removed []string)
- func DirectoryExists(path string) (bool, error)
- func FileExists(path string) (bool, error)
- func GetInt(request string) int
- func GetString(request string) string
- func IsDirectoryEmpty(path string) (bool, error)
- func IsEncrypted(dirpath string) bool
- func IsTinzenite(dirpath string) bool
- func LoadPeers(root string) (map[string]*Peer, error)
- func MakeDirectories(root string, subdirs ...string) error
- func MakeDirectory(path string) error
- func MakeEncryptedDir(root string) error
- func MakeTinzeniteDir(root string) error
- func NewIdentifier() (string, error)
- func ObjectExists(path string) (bool, error)
- func ReadDirectoryList() ([]string, error)
- func RemoveDirContents(path string) error
- func RemoveDotTinzenite(path string) error
- func SortString(list []string) []string
- func WriteDirectoryList(path string) error
- type Answer
- type AuthenticationMessage
- type Cmd
- type Communication
- type LockAction
- type LockMessage
- type Message
- type MsgType
- type NotifyMessage
- type NotifyType
- type ObjectInfo
- type ObjectType
- type Operation
- type Peer
- type PushMessage
- type Question
- type RelativePath
- func (r *RelativePath) Apply(path string) *RelativePath
- func (r *RelativePath) AtRoot() bool
- func (r *RelativePath) Depth() int
- func (r *RelativePath) FullPath() string
- func (r *RelativePath) LastElement() string
- func (r *RelativePath) RenameLastElement(value string) *RelativePath
- func (r *RelativePath) RootPath() string
- func (r *RelativePath) String() string
- func (r *RelativePath) SubPath() string
- func (r *RelativePath) Up() *RelativePath
- type RequestMessage
- type Sortable
- type SortableString
- type SortableUpdateMessage
- type ToxPeerDump
- type UpdateMessage
- type Version
Constants ¶
const ( /*RANDOMSEEDLENGTH is the amount of bytes used as cryptographic hash seed.*/ RANDOMSEEDLENGTH = 32 /*IDMAXLENGTH is the length in chars of new random identification hashes.*/ IDMAXLENGTH = 16 /*KEYLENGTH is the length of the encryption key used for challenges and file encryption.*/ KEYLENGTH = 256 /*FILEPERMISSIONMODE used for all file operations.*/ FILEPERMISSIONMODE = 0777 /*FILEFLAGCREATEAPPEND is the flag required to create a file or append to it if it already exists.*/ FILEFLAGCREATEAPPEND = os.O_CREATE | os.O_RDWR | os.O_APPEND /*CHUNKSIZE for hashing and encryption.*/ CHUNKSIZE = 8 * 1024 )
constant value here
const ( TINZENITEDIR = ".tinzenite" TINIGNORE = ".tinignore" // correct valid name of .tinignore files DIRECTORYLIST = "directory.list" LOCALDIR = "local" // info to the local peer is stored here TEMPDIR = "temp" RECEIVINGDIR = "receiving" // dir for receiving transfers SENDINGDIR = "sending" // send dir for now only used in encrypted REMOVEDIR = "removed" // remove REMOVECHECKDIR = "check" // remove REMOVEDONEDIR = "done" // remove REMOVESTOREDIR = "rmstore" // local remove check dir ORGDIR = "org" // only directory that IS synchronized as normal PEERSDIR = "peers" ENDING = ".json" AUTHJSON = "auth" + ENDING MODELJSON = "model" + ENDING SELFPEERJSON = "self" + ENDING BOOTJSON = "boot" + ENDING )
Path constants here
const ( STOREPEERDIR = TINZENITEDIR + "/" + ORGDIR + "/" + PEERSDIR STORETOXDUMPDIR = TINZENITEDIR + "/" + LOCALDIR STOREAUTHDIR = TINZENITEDIR + "/" + ORGDIR STOREMODELDIR = TINZENITEDIR + "/" + LOCALDIR )
Special path sets here. Mostly used to make writing to sub directories easier.
TODO aren't these all for core? Then move them there.
const ( /*OpUnknown operation.*/ OpUnknown = iota /*OpCreate operation.*/ OpCreate /*OpModify operation.*/ OpModify /*OpRemove operation.*/ OpRemove )
const IDMODEL = "MODEL"
IDMODEL is the model identification used to differentiate models from files.
const TINDIRIGNORE = "# DO NOT MODIFY!\n/" + LOCALDIR + "\n/" + TEMPDIR + "\n/" + RECEIVINGDIR + "\n/" + SENDINGDIR
.tinignore content for .tinzenite directory
Variables ¶
var ( ErrIllegalParameters = errors.New("illegal parameters given") ErrUnsupported = errors.New("feature currently unsupported") ErrIsTinzenite = errors.New("already a Tinzenite directory") ErrNotTinzenite = errors.New("path is not valid Tinzenite directory") ErrNoTinIgnore = errors.New("no .tinignore file found") ErrUntracked = errors.New("object is not tracked in the model") ErrNilInternalState = errors.New("internal state has illegal NIL values") ErrConflict = errors.New("conflict, can not apply") ErrIllegalFileState = errors.New("illegal file state detected") )
Errors of Tinzenite.
Functions ¶
func ContentHash ¶
ContentHash generates the hash of the content of the given file at path.
func Difference ¶
Difference takes the starting and target path lists and returns the operations required for each path to get from the starting to the target maps.
NOTE: Extra care has been taken that Difference does NOT modify the passed map references.
func DirectoryExists ¶
DirectoryExists checks whether a directory at that location exists.
func FileExists ¶
FileExists checks whether a file at that location exists.
func IsDirectoryEmpty ¶
IsDirectoryEmpty checks whether the given directory is empty.
func IsEncrypted ¶
IsEncrypted checks whether a given path is indeed a valid directory for an encrypted peer.
TODO detect incomplete dir (no connected peers, etc) or write a validate method
func IsTinzenite ¶
IsTinzenite checks whether a given path is indeed a valid directory
TODO detect incomplete dir (no connected peers, etc) or write a validate method
func MakeDirectories ¶
MakeDirectories creates a number of directories in the given root path. Useful if a complete directory tree has to be built at once.
func MakeEncryptedDir ¶
MakeEncryptedDir builds the directory structure for an encrypted peer. The given path is the path to the directory.
func MakeTinzeniteDir ¶
MakeTinzeniteDir creates the directory structure for the .tinzenite directory including the .tinignore file required for it. The given path is the path to the directory (NOT the .TINZENITEDIR!).
func NewIdentifier ¶
NewIdentifier creates a new random hash that is intended as identification strings for all manner of different objects. Length is IDMAXLENGTH.
func ObjectExists ¶
ObjectExists combines FileExists and DirectoryExists.
func ReadDirectoryList ¶
ReadDirectoryList reads all registered Tinzenite directories in the system. May return an empty listing if none found!
func RemoveDirContents ¶
RemoveDirContents removes all files within the given path, leaving the directory as is.
func RemoveDotTinzenite ¶
RemoveDotTinzenite directory. Specifically leaves all user files but removes all Tinzenite specific items.
func SortString ¶
SortString sorts an array of strings representing paths by length.
func WriteDirectoryList ¶
WriteDirectoryList adds the given path to the DIRECTORYLIST file. Will try to avoid writing the same path multiple times.
Types ¶
type Answer ¶
type Answer struct {
// contains filtered or unexported fields
}
Answer is a possible requested answer to a question.
type AuthenticationMessage ¶
AuthenticationMessage is the message used to authenticate trusted peers.
func CreateAuthenticationMessage ¶
func CreateAuthenticationMessage(encrypted []byte) AuthenticationMessage
CreateAuthenticationMessage is a convenience method for building an instance of the message.
func (*AuthenticationMessage) JSON ¶
func (am *AuthenticationMessage) JSON() string
JSON representation of this message.
func (*AuthenticationMessage) String ¶
func (am *AuthenticationMessage) String() string
type Cmd ¶
type Cmd int
Cmd is the enum for which operation the program should execute. Satisfies the Value interface so that it can be used in flag.
type Communication ¶
type Communication int
Communication is an enumeration for the available communication methods of Tinzenite peers.
const ( /*CmNone method.*/ CmNone Communication = iota /*CmTox protocol.*/ CmTox )
func (Communication) String ¶
func (cm Communication) String() string
type LockAction ¶
type LockAction int
LockAction defines what action a LockMessage is.
const ( /*LoNone is the default empty action.*/ LoNone LockAction = iota /*LoRequest is a request for a lock.*/ LoRequest /*LoRelease is a release request for a lock.*/ LoRelease /*LoAccept is used to notify of a successful previous operation.*/ LoAccept )
func (*LockAction) MarshalJSON ¶
func (lock *LockAction) MarshalJSON() ([]byte, error)
MarshalJSON overrides json.Marshal for this type.
func (LockAction) String ¶
func (lock LockAction) String() string
func (*LockAction) UnmarshalJSON ¶
func (lock *LockAction) UnmarshalJSON(data []byte) error
UnmarshalJSON overrides json.Unmarshal for this type.
type LockMessage ¶
type LockMessage struct { Type MsgType Action LockAction }
LockMessage is the message used to lock an encrypted peer.
func CreateLockMessage ¶
func CreateLockMessage(action LockAction) LockMessage
CreateLockMessage is a convenience method for building an instance of the message.
func (*LockMessage) JSON ¶
func (lm *LockMessage) JSON() string
JSON representation of this message.
func (*LockMessage) String ¶
func (lm *LockMessage) String() string
type Message ¶
type Message struct {
Type MsgType
}
Message is a base type for only reading out the operation to define the message type.
type MsgType ¶
type MsgType int
MsgType is used to define a message type.
const ( /*MsgNone default.*/ MsgNone MsgType = iota /*MsgUpdate is an UpdateMessage.*/ MsgUpdate /*MsgRequest is a RequestMessage.*/ MsgRequest /*MsgNotify is a NotifyMessage.*/ MsgNotify /*MsgLock is a LockMessage.*/ MsgLock /*MsgPush is a PushMessage.*/ MsgPush /*MsgChallenge is a ChallengeMessage.*/ MsgChallenge )
func (*MsgType) MarshalJSON ¶
MarshalJSON overrides json.Marshal for this type.
func (*MsgType) UnmarshalJSON ¶
UnmarshalJSON overrides json.Unmarshal for this type.
type NotifyMessage ¶
type NotifyMessage struct { Type MsgType Notify NotifyType Identification string ObjType ObjectType }
NotifyMessage is used to notify another peer of special cases.
func CreateNotifyMessage ¶
func CreateNotifyMessage(notify NotifyType, identification string, objType ObjectType) NotifyMessage
CreateNotifyMessage is a convenience method for building an instance of the message.
func (*NotifyMessage) JSON ¶
func (nm *NotifyMessage) JSON() string
JSON representation of this message.
func (*NotifyMessage) String ¶
func (nm *NotifyMessage) String() string
type NotifyType ¶
type NotifyType int
NotifyType defines what notify action a NotifyMessage is to be.
const ( /*NoNone is the default empty notify.*/ NoNone NotifyType = iota /*NoRemoved is the removed notification.*/ NoRemoved /*NoMissing is the missing notification.*/ NoMissing )
func (*NotifyType) MarshalJSON ¶
func (n *NotifyType) MarshalJSON() ([]byte, error)
MarshalJSON overrides json.Marshal for this type.
func (NotifyType) String ¶
func (n NotifyType) String() string
func (*NotifyType) UnmarshalJSON ¶
func (n *NotifyType) UnmarshalJSON(data []byte) error
UnmarshalJSON overrides json.Unmarshal for this type.
type ObjectInfo ¶
type ObjectInfo struct { Directory bool Identification string Name string Path string Shadow bool Version Version Content string `json:",omitempty"` Objects []*ObjectInfo `json:",omitempty"` }
ObjectInfo represents the in model object fully.
func CreateObjectInfo ¶
func CreateObjectInfo(root string, subpath string, selfid string) (*ObjectInfo, error)
CreateObjectInfo is a TEST function for creating an object for the specified parameters.
func (*ObjectInfo) Equal ¶
func (o *ObjectInfo) Equal(that *ObjectInfo) bool
Equal checks wether the given pointer points to the same object based on pointer and identification. NOTE: Does not compare any other properties!
func (*ObjectInfo) ForEach ¶
func (o *ObjectInfo) ForEach(f onEach)
ForEach is a helper function that applies the given function to the object and all its sub Objects.
func (*ObjectInfo) JSON ¶
func (o *ObjectInfo) JSON() string
JSON returns a json representation of this object.
func (*ObjectInfo) String ¶
func (o *ObjectInfo) String() string
type ObjectType ¶
type ObjectType int
ObjectType defines the type of Request or Push.
const ( /*OtNone is default empty request.*/ OtNone ObjectType = iota /*OtObject requests an object.*/ OtObject /*OtModel requests the model.*/ OtModel /*OtPeer requests the connected peers peer file.*/ OtPeer /*OtAuth requests the authentication file.*/ OtAuth )
func (*ObjectType) MarshalJSON ¶
func (ot *ObjectType) MarshalJSON() ([]byte, error)
MarshalJSON overrides json.Marshal for this type.
func (ObjectType) String ¶
func (ot ObjectType) String() string
func (*ObjectType) UnmarshalJSON ¶
func (ot *ObjectType) UnmarshalJSON(data []byte) error
UnmarshalJSON overrides json.Unmarshal for this type.
type Operation ¶
type Operation int
Operation is the enumeration for the possible protocol operations.
func (*Operation) MarshalJSON ¶
MarshalJSON overrides json.Marshal for this type.
func (*Operation) UnmarshalJSON ¶
UnmarshalJSON overrides json.Unmarshal for this type.
type Peer ¶
type Peer struct { Name string // user defined name for the peer Address string // tox address of the peer Protocol Communication // for now always Tox Trusted bool // if trusted peer (meaning it must satisfy a challenge) Identification string // internal ID of peer // contains filtered or unexported fields }
Peer is the communication representation of a Tinzenite peer.
func CreatePeer ¶
CreatePeer returns a peer object for the given parameters.
func (*Peer) IsAuthenticated ¶
IsAuthenticated returns the set value whether the Peer has been set as authenticated.
func (*Peer) SetAuthenticated ¶
SetAuthenticated allows to set whether a peer has been authenticated.
type PushMessage ¶
type PushMessage struct { Type MsgType Identification string ObjType ObjectType }
PushMessage is the message used to notify an encrypted peer of an incomming file transfer.
func CreatePushMessage ¶
func CreatePushMessage(identification string, ot ObjectType) PushMessage
CreatePushMessage is a convenience method for building an instance of the message.
func (*PushMessage) JSON ¶
func (pm *PushMessage) JSON() string
JSON representation of this message.
func (*PushMessage) String ¶
func (pm *PushMessage) String() string
type Question ¶
type Question struct {
// contains filtered or unexported fields
}
Question is a struct for variable user input.
func CreateQuestion ¶
CreateQuestion creates a new question object with the given question. Per default the answers are not case sensitive.
func CreateYesNo ¶
CreateYesNo creates a question with predeclared Yes and No answer options. The Option for No is negative, for Yes positive.
func (*Question) CreateAnswer ¶
CreateAnswer creates an answer for the given question.
type RelativePath ¶
type RelativePath struct {
// contains filtered or unexported fields
}
RelativePath implements a path consisting of a base path and any subpath that lies beneath it.
func CreatePath ¶
func CreatePath(root string, subpath string) *RelativePath
CreatePath creates a path directly with a subpath selected. Note that the subpath is NOT checked if it is relative or absolute: to do that use CreatePathRoot directly followed by Apply, which will check.
func CreatePathRoot ¶
func CreatePathRoot(root string) *RelativePath
CreatePathRoot creates a RelativePath with the given root path.
func (*RelativePath) Apply ¶
func (r *RelativePath) Apply(path string) *RelativePath
Apply does two different things depending on the path given. If path begins with "/" it is considered an absolute path and must match the root of the calling path. Otherwise the path is applied as a new sub path, replacing the old value.
func (*RelativePath) AtRoot ¶
func (r *RelativePath) AtRoot() bool
AtRoot signals whether the path has any sub path.
func (*RelativePath) Depth ¶
func (r *RelativePath) Depth() int
Depth is the amount of elements contained in the full path.
func (*RelativePath) FullPath ¶
func (r *RelativePath) FullPath() string
FullPath returns the full path of the path.
func (*RelativePath) LastElement ¶
func (r *RelativePath) LastElement() string
LastElement returns the last element of the complete path.
func (*RelativePath) RenameLastElement ¶
func (r *RelativePath) RenameLastElement(value string) *RelativePath
RenameLastElement overwrites the last element completely with the given value and returns the corresponding new RelativePath.
func (*RelativePath) RootPath ¶
func (r *RelativePath) RootPath() string
RootPath returns the root path.
func (*RelativePath) String ¶
func (r *RelativePath) String() string
func (*RelativePath) SubPath ¶
func (r *RelativePath) SubPath() string
SubPath returns the current sub path.
func (*RelativePath) Up ¶
func (r *RelativePath) Up() *RelativePath
Up removes the last element from the path, up to the root path (and no further!).
type RequestMessage ¶
type RequestMessage struct { Type MsgType ObjType ObjectType Identification string }
RequestMessage is used to trigger the sending of messages or files from other peers.
func CreateRequestMessage ¶
func CreateRequestMessage(ot ObjectType, identification string) RequestMessage
CreateRequestMessage is a convenience method for building an instance of the message.
func (*RequestMessage) JSON ¶
func (rm *RequestMessage) JSON() string
JSON representation of this message.
func (*RequestMessage) String ¶
func (rm *RequestMessage) String() string
type SortableString ¶
type SortableString []string
SortableString is a string slice that can be sorted by length.
func (SortableString) Len ¶
func (s SortableString) Len() int
func (SortableString) Less ¶
func (s SortableString) Less(i, j int) bool
func (SortableString) Swap ¶
func (s SortableString) Swap(i, j int)
type SortableUpdateMessage ¶
type SortableUpdateMessage []*UpdateMessage
SortableUpdateMessage allows the sorting of UpdateMessages
func (SortableUpdateMessage) Len ¶
func (s SortableUpdateMessage) Len() int
func (SortableUpdateMessage) Less ¶
func (s SortableUpdateMessage) Less(i, j int) bool
func (SortableUpdateMessage) Swap ¶
func (s SortableUpdateMessage) Swap(i, j int)
type ToxPeerDump ¶
ToxPeerDump stores the self peer information along with the tox binary data required for it to work.
func LoadToxDumpFrom ¶
func LoadToxDumpFrom(path string) (*ToxPeerDump, error)
LoadToxDumpFrom loads the toxPeerDump file from the given path.
func (*ToxPeerDump) StoreTo ¶
func (t *ToxPeerDump) StoreTo(path string) error
StoreTo the toxPeerDump to the given path.
type UpdateMessage ¶
type UpdateMessage struct { Type MsgType Operation Operation Object ObjectInfo }
UpdateMessage contains the relevant information for notifiying peers of updates.
func CreateUpdateMessage ¶
func CreateUpdateMessage(op Operation, obj ObjectInfo) UpdateMessage
CreateUpdateMessage is a convenience method for building an instance of the message.
func (*UpdateMessage) JSON ¶
func (um *UpdateMessage) JSON() string
JSON representation of this message.
func (*UpdateMessage) String ¶
func (um *UpdateMessage) String() string
type Version ¶
Version implements a vector clock. The value of zero should never turn up.
func (Version) Includes ¶
Includes returns true if the version contains all knowledge and version of the given version. Method is intended to allow ordering of versions.
func (Version) Increase ¶
Increase the version for the given peer based on the already existing versions.