utils

package
v0.0.0-...-e39d8f4 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2021 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SimpleModeStr : string containing the name for gossiper simple mode
	SimpleModeStr string = "simple"

	// RumorModeStr : string containing the name for gossiper rumor mode
	RumorModeStr string = "rumor"

	// TimeoutValue : timeout value in seconds
	TimeoutValue int = 10

	// AntiEntropyDefault : default value in seconds for anti entropy
	AntiEntropyDefault int = 10

	// RTimerDefault is the defaut value for rtimer
	RTimerDefault int = 0

	// LocalhostAddr : "127.0.0.1"
	LocalhostAddr string = "127.0.0.1"

	// DefaultUIPort : 8080
	DefaultUIPort string = "8080"

	// DefaultGUIPort : 8080
	DefaultGUIPort string = "8080"

	// PrivateMessageID is the ID for private messages
	PrivateMessageID uint32 = 0

	// DefaultHopLimit default hop limit for private messages
	DefaultHopLimit uint32 = 10

	// SharedFolderName path to the gossiper's shared folder
	SharedFolderName string = "_SharedFiles"

	// DownloadsFolderName path to the gossiper's downloads folder
	DownloadsFolderName string = "_Downloads"

	// Filemode is file mode for the shared and download folders
	Filemode os.FileMode = 0666

	// ChunkSize size of a file chunk to send (8KB)
	ChunkSize int = 8192 // 8 KB

	// BufferSize : read buffer size in bytes
	BufferSize int = ChunkSize + 2048

	// ShaSize length of a sha hash in bytes
	ShaSize int = sha256.Size

	// FileTimout timeout value for file requests in seconds
	FileTimout int = 5

	// DefaultSearchBudget default search budget
	DefaultSearchBudget uint64 = 2

	// NoSearchBudget default search budget if not given as argument
	NoSearchBudget int = 0

	// MaxSearchBudget max search budget
	MaxSearchBudget uint64 = 32

	// DefaultGossiperName default gossiper name
	DefaultGossiperName string = "Gossiper"

	// DefaultDuplicateSearchTime default time in which the same search request
	// is considered as duplicate
	DefaultDuplicateSearchTime time.Duration = 500 * time.Millisecond

	// SearchPeriod search requests should be sent periodically with this
	// period
	SearchPeriod time.Duration = time.Second

	// MatchThreshold threshold of search matchs
	MatchThreshold int = 2

	// DefaultPeerNumber default N
	DefaultPeerNumber int = 3

	// StubbornTimeoutDefault in seconds
	StubbornTimeoutDefault int = 5

	// UnconfirmedInt value for TLCMessage confirmed
	UnconfirmedInt int = -1

	// OwnTLCBufferSize OwnTLCBufferSize
	OwnTLCBufferSize int = 50
	// OutsideTLCBufferSize OutsideTLCBufferSize
	OutsideTLCBufferSize int = 200

	// SecurityLimit for iterating on blocks and hashs
	SecurityLimit int = 100
)

Variables

This section is empty.

Functions

func CheckFilename

func CheckFilename(name string) error

CheckFilename check if the filename is correct and return an error if not

func ChooseCRandomAmongN

func ChooseCRandomAmongN(c, n int) []int

ChooseCRandomAmongN select c distinct random number between 0 and n

func EqualAddr

func EqualAddr(addr1, addr2 net.UDPAddr) bool

EqualAddr : compares the given UDPAddr, returns false if they are different and true otherwise

func FieldCounter

func FieldCounter(p *GossipPacket) int

FieldCounter count the number of fields in a GossipPacket

func FlattenKeywords

func FlattenKeywords(old []string) string

FlattenKeywords flatten list of string to single string

func GetAckIdentifier

func GetAckIdentifier(origin, peer string, id uint32) string

GetAckIdentifier get the unique message identifier associated with the given parameters. origin: Origin of the acked message peer: peer with whom the gossip is exchanged id: Id of the gossip

func GetRand

func GetRand(n int) int

GetRand : returns a "fake" random number (the same at all executions)

func GetRealRand

func GetRealRand(n int) int

GetRealRand : returns a really random number generated with crypto package

func IntInSlice

func IntInSlice(a int, list []int) bool

IntInSlice return true if a is in slice list

func ParsePeers

func ParsePeers(peerList *string) *[]net.UDPAddr

ParsePeers : infe

func ProtobufGossip

func ProtobufGossip(msg *GossipPacket) []byte

ProtobufGossip : encapsulates a gossip message using protobuf

func ProtobufMessage

func ProtobufMessage(msg *Message) []byte

ProtobufMessage : encapsulate a client message using protobuf

func RemoveAddrFromPeers

func RemoveAddrFromPeers(peers []net.UDPAddr, addr net.UDPAddr) []net.UDPAddr

RemoveAddrFromPeers : remove the given address from the array of addresses

func SameSearch

func SameSearch(search SearchStatus, req SearchRequest) bool

SameSearch compare a search status with a search request, return true if the search is the same

func SplitKeywords

func SplitKeywords(kw string) []string

SplitKeywords given a string, split the keywords separated by comas and returns a list of keyword strings

func SyncMapCount

func SyncMapCount(sm *sync.Map) uint32

SyncMapCount : count the number of elements in a sync map

func TestMessageType

func TestMessageType(p *GossipPacket) bool

TestMessageType : test if the packet only contains a message type and prints an error and returns false if it is not the case

Types

type AckValues

type AckValues struct {
	Channel        *chan bool
	InitialMessage GossipPacket
}

AckValues : values pointed by an AckIdentifier

type BlockPublish

type BlockPublish struct {
	PrevHash    [32]byte
	Transaction TxPublish
}

BlockPublish block publish structure

func (*BlockPublish) Hash

func (b *BlockPublish) Hash() (out [32]byte)

Hash function of BlockPublish

type DataReply

type DataReply struct {
	Origin      string
	Destination string
	HopLimit    uint32
	HashValue   []byte
	Data        []byte
}

DataReply data reply packets

type DataRequest

type DataRequest struct {
	Origin      string
	Destination string
	HopLimit    uint32
	HashValue   []byte
}

DataRequest data request packets

type FileChunk

type FileChunk struct {
	File   *FileStruct
	Number int
	Hash   ShaHash
	Data   []byte
}

FileChunk one chunk of data of a file

type FileRequestStatus

type FileRequestStatus struct {
	File          *FileStruct
	Destination   [][]string
	MetafileOK    bool
	PendingChunks []ShaHash
	ChunkCount    int
	Ack           chan bool
}

FileRequestStatus status for a file request

type FileStatusList

type FileStatusList struct {
	sync.Mutex
	List []FileRequestStatus
}

FileStatusList list of file request statuses

type FileStruct

type FileStruct struct {
	Name         string
	MetafileHash ShaHash
	Size         int64
	Metafile     []byte
	NChunks      int
	Chunks       map[ShaHash]*FileChunk
	Done         bool
}

FileStruct file structure containing file's metadata stored on the gossiper

type GossipPacket

type GossipPacket struct {
	Simple        *SimpleMessage
	Rumor         *RumorMessage
	Status        *StatusPacket
	Private       *PrivateMessage
	DataRequest   *DataRequest
	DataReply     *DataReply
	SearchRequest *SearchRequest
	SearchReply   *SearchReply
	TLCMessage    *TLCMessage
	Ack           *TLCAck
}

GossipPacket : default gossip packet used by the Peerster

func UnprotobufGossip

func UnprotobufGossip(packet []byte) (*GossipPacket, bool)

UnprotobufGossip : decapsulate a gossip message using protobuf

type List

type List struct {
	Size      int
	Tail      *Node
	Start     *Node
	Filenames []string
}

List double linked list structure

func (*List) InsertNode

func (l *List) InsertNode(newNode *Node)

InsertNode to double linked list

type Message

type Message struct {
	Text        string
	Destination *string
	File        *string
	Request     *[]byte
	Budget      *uint64
	Keywords    *[]string
}

Message : simple message type that client send to gossiper

func UnprotobufMessage

func UnprotobufMessage(packet []byte) (*Message, bool)

UnprotobufMessage : decapsulate a gossip message using protobuf

type Node

type Node struct {
	Block BlockPublish
	Hash  ShaHash
	Prev  *Node
	Next  *Node
}

Node of double linked list

type PeerStatus

type PeerStatus struct {
	Identifier string
	NextID     uint32
}

PeerStatus : a status is useful to ask a peer some packets

type PrivateMessage

type PrivateMessage struct {
	Origin      string
	ID          uint32
	Text        string
	Destination string
	HopLimit    uint32
}

PrivateMessage : private message structure

type Queue

type Queue struct {
	// contains filtered or unexported fields
}

Queue is a basic FIFO queue based on a circular list that resizes as needed.

func NewQueue

func NewQueue(size int) *Queue

NewQueue returns a new queue with the given initial size.

func (*Queue) Pop

func (q *Queue) Pop() *TxPublish

Pop removes and returns a node from the queue in first to last order.

func (*Queue) Push

func (q *Queue) Push(n *TxPublish)

Push adds a node to the queue.

type RumorMessage

type RumorMessage struct {
	Origin string
	ID     uint32
	Text   string
}

RumorMessage : Rumor message containing the original sender's name, a sequence number and the content. The message should be uniquely identified by the combination of Origin and ID

type SearchFile

type SearchFile struct {
	Name         string
	MetafileHash ShaHash
	Chunks       map[uint64]map[string]bool
	NChunks      uint64
	Complete     bool
}

SearchFile search file structure

type SearchReply

type SearchReply struct {
	Origin      string
	Destination string
	HopLimit    uint32
	Results     []*SearchResult
}

SearchReply search reply packet

type SearchRequest

type SearchRequest struct {
	Origin   string
	Budget   uint64
	Keywords []string
}

SearchRequest search request packet

type SearchResult

type SearchResult struct {
	FileName     string
	MetafileHash []byte
	ChunkMap     []uint64
	ChunkCount   uint64
}

SearchResult search result included in search reply

type SearchStatus

type SearchStatus struct {
	Origin   string
	Keywords map[string]bool
}

SearchStatus search status kept at the gossiper

type ShaHash

type ShaHash [ShaSize]byte

ShaHash is the struct of hash Sha256

type SimpleMessage

type SimpleMessage struct {
	OriginalName  string
	RelayPeerAddr string
	Contents      string
}

SimpleMessage : a simple message structure containing the original sender's name, the relay peer address, and the content of the message

type StatusPacket

type StatusPacket struct {
	Want []PeerStatus
}

StatusPacket : a StatusPacket is a packet containing a list of PeerStatus that are wanted by the sender

type SyncNewMessages

type SyncNewMessages struct {
	sync.Mutex
	Messages []RumorMessage
}

SyncNewMessages : sync slice of rumor messages

type TLCAck

type TLCAck PrivateMessage

TLCAck TLC message acknowledgement

type TLCMessage

type TLCMessage struct {
	Origin      string
	ID          uint32
	Confirmed   int
	TxBlock     BlockPublish
	VectorClock *StatusPacket
	Fitness     float32
}

TLCMessage structure

type TxPublish

type TxPublish struct {
	Name         string
	Size         int64
	MetafileHash []byte
}

TxPublish transaction publish structure

func (*TxPublish) Hash

func (t *TxPublish) Hash() (out [32]byte)

Hash function of TxPublish

Jump to

Keyboard shortcuts

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