Documentation ¶
Index ¶
- Constants
- Variables
- func Decrypt(ciphertext []byte, nonce Nonce, key SymmetricKey) ([]byte, error)
- func DuplicateMap(data map[Hash]Login) map[Hash]Login
- func Encrypt(data []byte, key SymmetricKey) (EncryptedData, Nonce, error)
- func Generate() (PublicKey, PrivateKey, SymmetricKey, error)
- func HashToBytes(h Hash) []byte
- func NewSecret(userID, masterPassword string) (Secret, Salt, error)
- func NonceToBytes(nonce Nonce) []byte
- func ParsePeers(peerList string) []net.UDPAddr
- func Passphrase() (string, error)
- func PrintStatuses(h Hash, statuses []*LookupStatus)
- func RandInt(n int64) int64
- func RandomBytes(size uint) ([]byte, error)
- func SaltToBytes(salt Salt) []byte
- func SignatureToBytes(signature Signature) []byte
- func SymmetricKeyToBytes(symmK SymmetricKey) []byte
- func Timeout(timeout time.Duration) *chan bool
- func Verify(data []byte, signature Signature, key PublicKey) bool
- type Account
- func (account Account) AddLogin(loginClient LoginClient, loginPassword string, keysClient KeysClient) (Account, error)
- func (account Account) DeleteLogin(ID Hash, sk PrivateKey) (Account, error)
- func (account Account) GetLoginClientList(symmK SymmetricKey) ([]LoginClient, error)
- func (account Account) GetLoginPassword(loginClient LoginClient, symmK SymmetricKey) ([]byte, error)
- func (account Account) GetSignData() []byte
- func (account Account) Sign(sk PrivateKey) Account
- func (account Account) ToAccountClient(ID string, secret Secret) (AccountClient, error)
- func (account Account) ToAccountNetwork() AccountNetwork
- func (account Account) UpdateLoginPassword(ID Hash, loginPassword string, keysClient KeysClient) (Account, error)
- func (account Account) Verify() bool
- type AccountClient
- type AccountInfo
- type AccountMessage
- type AccountMetaData
- type AccountNetwork
- type Accounts
- type Bucket
- type BucketElement
- type Client
- type ClientMessage
- type Credentials
- type EncryptedData
- type Hash
- type Keys
- type KeysClient
- type Login
- type LoginClient
- type LoginMetaData
- type LookupStatus
- type Message
- type MessageCounter
- type NodeAddr
- type Nonce
- type Passtor
- func (p *Passtor) AddPeerToBucket(addr NodeAddr)
- func (p *Passtor) Allocate(id Hash, repl uint32, data AccountNetwork) []NodeAddr
- func (p *Passtor) AllocateToPeer(id Hash, peer NodeAddr, index, repl uint32, data AccountNetwork) error
- func (p *Passtor) Delete(id Hash)
- func (p *Passtor) FetchData(h *Hash, threshold float64) *Account
- func (p *Passtor) FetchDataFromPeer(h *Hash, peer NodeAddr) *Message
- func (p *Passtor) GetBucketID(val *Hash) uint16
- func (p *Passtor) GetKCloser(h *Hash) []NodeAddr
- func (p *Passtor) HandleAllocation(msg Message)
- func (p *Passtor) HandleClientMessage(accounts Accounts, message ClientMessage) *ServerResponse
- func (p *Passtor) HandleFetch(msg Message)
- func (p *Passtor) HandleMessage(protobufed []byte)
- func (p *Passtor) JoinDHT(peers []net.UDPAddr)
- func (p *Passtor) ListenToClients()
- func (p *Passtor) ListenToPasstors()
- func (p *Passtor) LookupRep(req Message)
- func (p *Passtor) LookupReq(hash *Hash) []NodeAddr
- func (p *Passtor) Ping(peer net.UDPAddr, retries int) bool
- func (p *Passtor) PrintBuckets()
- func (p *Passtor) Republish(account AccountInfo)
- func (p *Passtor) SendMessage(msg Message, dst net.UDPAddr, retries int) *Message
- func (p *Passtor) SetIdentity()
- func (p *Passtor) Store(newAccount Account, repl uint32) error
- type Printer
- type PrivateKey
- type PublicKey
- type Salt
- type Secret
- type ServerResponse
- type Signature
- type SymmetricKey
Constants ¶
const ( // DHTK K parameter for DHT K-buckets DHTK = 5 // ALPHA DHT concurrency parameter ALPHA = 2 // REPL replication factor REPL = 3 // NREQ minimal number of response after Fetch NREQ = 2 // THRESHOLD of answers before returning THRESHOLD = 0.333 // TIMEOUT value when waiting for an answer TIMEOUT = 1 * time.Second // MINRETRIES min number of attemps before giving up reaching an host MINRETRIES = 1 // MAXRETRIES max number of attemps before giving up reaching an host MAXRETRIES = 4 // BUFFERSIZE size of the udp connection read buffer BUFFERSIZE = 8192 // BYTELENGTH number of bits in a byte BYTELENGTH uint16 = 8 // PASSPHRASELENGHT default length in words for a passphrase PASSPHRASELENGHT = 8 // PASSPHRASESEP default word seperator in a passphrase PASSPHRASESEP = "." // V0 verbose level 0 (no output) V0 = 0 // V1 verbose level 1 (normal output) V1 = 1 // V2 verbose level 2 (mode verbose) V2 = 2 // V3 verbose level 3 (mode verbose++) V3 = 3 // TCPMAXPACKETSIZE is the largest size in bytes of a TCP packet TCPMAXPACKETSIZE = 65535 // REPUBLISHINTERVAL average time interval between republish in minutes REPUBLISHINTERVAL = 5 )
const ( // SALTLENGTH is the length of the salt to be used by Argon2 as KDF SALTLENGTH = 16 // ARGONITERATIONS is the number of iterations to be used in the Argon2 algo ARGONITERATIONS = 3 // ARGONMEMORY is the size in bytes to be used by Argon2 in memory ARGONMEMORY = 64 * 1024 // ARGONPARALELLISM is the number of cores to be used by Argon2 ARGONPARALELLISM = 2 // SECRETLENGTH is the length of the key produced by Argon2 SECRETLENGTH = SYMMKEYSIZE )
const HASHSIZE = 64
HASHSIZE size of a hash in byte
const ( // NONCESIZE size in bytes for a nonce NONCESIZE = chacha20poly1305.NonceSizeX )
const ( // SIGNATURESIZE size in bytes for a signature SIGNATURESIZE = ed25519.SignatureSize )
const ( // SYMMKEYSIZE size in bytes for a symmetric key SYMMKEYSIZE = chacha20poly1305.KeySize )
Variables ¶
var ALREADYSTORED = "Account already stored and up-to-date"
ALREADYSTORED error string
var NOERROR = ""
NOERROR string
Functions ¶
func Decrypt ¶
func Decrypt(ciphertext []byte, nonce Nonce, key SymmetricKey) ([]byte, error)
Decrypt decrypts the given ciphertext under the given key
func Encrypt ¶
func Encrypt(data []byte, key SymmetricKey) (EncryptedData, Nonce, error)
Encrypt encrypts the given data under the given key using ChaCha20 stream cipher
func Generate ¶
func Generate() (PublicKey, PrivateKey, SymmetricKey, error)
func HashToBytes ¶
func NonceToBytes ¶
func ParsePeers ¶
ParsePeers parse peer list in string format to udp addresses
func Passphrase ¶
func PrintStatuses ¶
func PrintStatuses(h Hash, statuses []*LookupStatus)
PrintStatuses print given lookup statuses
func RandomBytes ¶
RandomBytes generates an array of random bytes of the given size
func SaltToBytes ¶
func SignatureToBytes ¶
func SymmetricKeyToBytes ¶
func SymmetricKeyToBytes(symmK SymmetricKey) []byte
SymmetricKeyToBytes converts a symmetric key to a raw array of bytes
Types ¶
type Account ¶
type Account struct { ID Hash Keys Keys Version uint32 Data map[Hash]Login MetaData AccountMetaData Signature Signature }
Account groups everything that has been stored by a single user.
func MostRepresented ¶
MostRepresented returns the most represented verified (in the sense of signature equality)
func (Account) AddLogin ¶
func (account Account) AddLogin(loginClient LoginClient, loginPassword string, keysClient KeysClient) (Account, error)
func (Account) DeleteLogin ¶
func (account Account) DeleteLogin(ID Hash, sk PrivateKey) (Account, error)
func (Account) GetLoginClientList ¶
func (account Account) GetLoginClientList(symmK SymmetricKey) ([]LoginClient, error)
func (Account) GetLoginPassword ¶
func (account Account) GetLoginPassword(loginClient LoginClient, symmK SymmetricKey) ([]byte, error)
func (Account) GetSignData ¶
func (Account) Sign ¶
func (account Account) Sign(sk PrivateKey) Account
func (Account) ToAccountClient ¶
func (account Account) ToAccountClient(ID string, secret Secret) (AccountClient, error)
func (Account) ToAccountNetwork ¶
func (account Account) ToAccountNetwork() AccountNetwork
func (Account) UpdateLoginPassword ¶
type AccountClient ¶
type AccountClient struct { ID string Keys KeysClient }
Account used only client side to store info about the current user.
func (AccountClient) GetID ¶
func (accountClient AccountClient) GetID() Hash
func (AccountClient) ToEmptyAccount ¶
func (accountClient AccountClient) ToEmptyAccount(secret Secret, secretSalt Salt) (Account, error)
type AccountMessage ¶
type AccountMessage struct { Account AccountNetwork Repl uint32 }
AccountMessage message requesting a node to allocate a file or fetching an account info
type AccountMetaData ¶
AccountMetaData for the Account structure.
func (AccountMetaData) Hash ¶
func (accountMetaData AccountMetaData) Hash() Hash
type AccountNetwork ¶
type AccountNetwork struct { ID Hash Keys Keys Version uint32 Data []Login MetaData AccountMetaData Signature Signature }
AccountNetwork used to be able to encode to be sent over the network
func (AccountNetwork) ToAccount ¶
func (accountNetwork AccountNetwork) ToAccount() Account
type Accounts ¶
type Accounts map[Hash]*AccountInfo
Accounts is the collection of all created accounts.
type Bucket ¶
type Bucket struct { Mutex *sync.Mutex Head *BucketElement Tail *BucketElement Size uint }
Bucket structure representing Kademlia k-buckets
func (*Bucket) Find ¶
func (b *Bucket) Find(nodeAddr *NodeAddr) *BucketElement
Find and return the element corresponding to the given address, returns nil if not found
func (*Bucket) MoveToHead ¶
func (b *Bucket) MoveToHead(el *BucketElement)
MoveToHead moves an element of the list to the head
func (*Bucket) Replace ¶
func (b *Bucket) Replace(old *BucketElement, new *NodeAddr)
Replace the a node address in the list by a new one
type BucketElement ¶
type BucketElement struct { NodeAddr *NodeAddr Next *BucketElement Prev *BucketElement }
BucketElement represent individual elements of the k-buckets
type Client ¶
type Client struct { App *tview.Application Node string AccountClient AccountClient Account Account }
type ClientMessage ¶
type ClientMessage struct { Push *AccountNetwork Pull *Hash }
ClientMessage represents a message than can be sent from a client to a node
type Credentials ¶
type Credentials struct { Username EncryptedData Password EncryptedData }
Credentials for a given service.
func (Credentials) Hash ¶
func (credentials Credentials) Hash() Hash
type Hash ¶
Hash is a flexible type to handle hashes
var MAXDISTANCE Hash
MAXDISTANCE maximum distance between two hashes
func BytesToHash ¶
func GetKeysSorted ¶
func HashLogins ¶
func (Hash) Compare ¶
Compare two hashes, returns 1 if first hash smaller than the second, -1 if the second is smaller than the first, and 0 if they are equal
func (Hash) PrintDistancesToHash ¶
PrintDistancesToHash print the distance from a list of node addresses to a hash
type Keys ¶
type Keys struct { PublicKey PublicKey PrivateKeySeed EncryptedData SymmetricKey EncryptedData }
Keys used to encrypt, or sign data.
func (Keys) ToKeysClient ¶
type KeysClient ¶
type KeysClient struct { PublicKey PublicKey PrivateKey PrivateKey SymmetricKey SymmetricKey }
KeysClient used only client side to store the keys used to sign or en/de-crypt data.
func (KeysClient) Hash ¶
func (keysClient KeysClient) Hash() Hash
type Login ¶
type Login struct { ID Hash Service EncryptedData Credentials Credentials MetaData LoginMetaData }
Login is a tuple of credentials and corresponding metadata to ensure validity.
func (Login) ToLoginClient ¶
func (login Login) ToLoginClient(symmK SymmetricKey) (LoginClient, error)
type LoginClient ¶
LoginClient used to display restricted plaintext info about a login
func (LoginClient) GetID ¶
func (loginClient LoginClient) GetID(symmK SymmetricKey) Hash
func (LoginClient) ToNewLogin ¶
func (loginClient LoginClient) ToNewLogin(keysClient KeysClient, loginPassword string) (Login, error)
type LoginMetaData ¶
LoginMetaData for the Login structure.
func (LoginMetaData) Hash ¶
func (logInMetaData LoginMetaData) Hash() Hash
type LookupStatus ¶
LookupStatus type used by the lookup RPC
func NewLookupStatus ¶
func NewLookupStatus(nodeAddr NodeAddr) *LookupStatus
NewLookupStatus returns new lookup status structure for given nodeaddr
type Message ¶
type Message struct { ID uint64 // message ID Reply bool // message is a reply Sender *NodeAddr // sender identity Ping *bool // non nil if message is a ping message LookupReq *Hash // value to lookup LookupRep *[]NodeAddr // lookup response AllocationReq *AccountMessage AllocationRep *string FetchReq *Hash FetchRep *AccountMessage }
Message structure defining messages exchanged between passtors
type MessageCounter ¶
type MessageCounter struct { Mutex *sync.Mutex // mutex of the structure IDCounter *uint64 // current message ID PendingMsg map[uint64]*chan Message // list of current pending messages }
MessageCounter structure containing message indexing tools
func (MessageCounter) GetMessageID ¶
func (c MessageCounter) GetMessageID() uint64
GetMessageID get the next message ID, ids starting at 1
type NodeAddr ¶
type NodeAddr struct { Addr net.UDPAddr // udp address (ip + port) of the node NodeID Hash // nodeID of that node }
NodeAddr node address entry in the k-bucket, node udp ip and port, and nodeID
type Nonce ¶
Nonce format for encryption
func BytesToNonce ¶
BytesToNonce converts a byte array to a Nonce type.
type Passtor ¶
type Passtor struct { Name string // name of the passtor instance NodeID Hash // hash of the name of the passtor, node identifier PConn *net.UDPConn // udp socket to communicate with other passtors ClientAddr *net.TCPAddr // tcp address to communicate with clients Messages *MessageCounter // handles message id and pending messages Addr NodeAddr // address used to communicate with passtors Buckets map[uint16]*Bucket // k-buckets used in the DHT Printer Printer // passtor console printer Accounts Accounts }
Passtor instance
func NewPasstor ¶
NewPasstor creates and return a new Passtor instance
func (*Passtor) AddPeerToBucket ¶
AddPeerToBucket check if a peer should be added to the DHT, and if yes, add it to the appropriate bucket
func (*Passtor) Allocate ¶
func (p *Passtor) Allocate(id Hash, repl uint32, data AccountNetwork) []NodeAddr
Allocate given data identified by the given id to the given replication factor appropriate peers
func (*Passtor) AllocateToPeer ¶
func (p *Passtor) AllocateToPeer(id Hash, peer NodeAddr, index, repl uint32, data AccountNetwork) error
AllocateToPeer allocate some data to a peer, returns true on success, false if cannot reach peer or error
func (*Passtor) FetchDataFromPeer ¶
FetchDataFromPeer send fetch request to given peer, returns the reply of the remote host
func (*Passtor) GetBucketID ¶
GetBucketID get the bucket identifier in which val belongs
func (*Passtor) GetKCloser ¶
GetKCloser get the K closer nodes to given hash
func (*Passtor) HandleAllocation ¶
HandleAllocation handles an allocation on the remote peer
func (*Passtor) HandleClientMessage ¶
func (p *Passtor) HandleClientMessage(accounts Accounts, message ClientMessage) *ServerResponse
func (*Passtor) HandleFetch ¶
HandleFetch searches for requested file, send it if it finds it
func (*Passtor) HandleMessage ¶
HandleMessage handles incoming messages
func (*Passtor) JoinDHT ¶
JoinDHT passtor join the DHT connect to bootstrap peers given as argument lookup for self to fill k-buckets
func (*Passtor) ListenToClients ¶
func (p *Passtor) ListenToClients()
func (*Passtor) ListenToPasstors ¶
func (p *Passtor) ListenToPasstors()
ListenToPasstors listen on the udp connection used to communicate with other passtors, and distribute received messages to HandleMessage()
func (*Passtor) PrintBuckets ¶
func (p *Passtor) PrintBuckets()
PrintBuckets print all bucket with their state
func (*Passtor) Republish ¶
func (p *Passtor) Republish(account AccountInfo)
Republish account information in the DHT, called periodically
func (*Passtor) SendMessage ¶
SendMessage send the given message to the remote peer over udp returns the reply message once it has arrived
func (*Passtor) SetIdentity ¶
func (p *Passtor) SetIdentity()
SetIdentity set the identity of the passtor instance to the hash of the given name
type Printer ¶
Printer of the passtor, handles all prints to console
type PrivateKey ¶
type PrivateKey = ed25519.PrivateKey
PrivateKey type
func SeedToPrivateKey ¶
func SeedToPrivateKey(seed []byte) PrivateKey
type Secret ¶
type Secret = SymmetricKey
Secret is the secret used by the user to locally decrypt its symmetric key K and secret key sk
func ComputeSecret ¶
func KDFToSecret ¶
type ServerResponse ¶
type ServerResponse struct { Status string Debug *string Data *AccountNetwork }
ServerResponse represents a response from a node to a client
type Signature ¶
type Signature [SIGNATURESIZE]byte
Signature format
func BytesToSignature ¶
func Sign ¶
func Sign(data []byte, key PrivateKey) Signature
Sign computes the signature of the given message under the given private key
type SymmetricKey ¶
type SymmetricKey [SYMMKEYSIZE]byte
SymmetricKey format
func BytesToSymmetricKey ¶
func BytesToSymmetricKey(array []byte) SymmetricKey
BytesToSymmetricKey creates a symmetric key from an array of bytes