Documentation ¶
Index ¶
- Constants
- Variables
- type Chunk
- type ChunkID
- type ChunkIDs
- type FileHash
- type FileHashTmp
- type FileID
- type FileState
- type LocalStorage
- type LocalStorageConfig
- type P2PFile
- type P2PFileStorage
- type P2PRemoteStorage
- type P2PStorage
- func (s *P2PStorage) AddFile(fileData []byte) (FileID, error)
- func (s *P2PStorage) AddReceivedFileChunks(hash FileID, chunks []Chunk) error
- func (s *P2PStorage) DeleteData(hash FileID) error
- func (s *P2PStorage) GetChunkIDsInStorage(hash FileID) ([]ChunkID, error)
- func (s *P2PStorage) GetFileData(hash FileID) ([]byte, error)
- func (s *P2PStorage) GetRequestedChunks(hash FileID, ids []ChunkID) ([]Chunk, error)
- type PeerID
- type PeerStorage
Constants ¶
const LocalStorageSize = 100
Variables ¶
var FILENOTFOUND = errors.New("P2PFile not in storage")
Functions ¶
This section is empty.
Types ¶
type Chunk ¶
Chunk represents a chunk of content
func FileDataToChunks ¶
FileDataToChunks: Transform array of bytes (content of a file) into Chunk's array with 'chunkSize' size.
type FileHash ¶
type FileHash []byte
FileHash:
func NewHashFromFile ¶
NewHashFromFile: Create a New Hashfrom file's content with SHA256
type FileHashTmp ¶
type FileHashTmp int
func (FileHashTmp) String ¶
func (f FileHashTmp) String() string
type FileState ¶
type FileState int
FileState: State of a file, representing if it's complete, updated or unchanged
type LocalStorage ¶
type LocalStorage interface { AddFile(fileData []byte) (FileID, error) AddReceivedFileChunks(hash FileID, chunks []Chunk) error GetRequestedChunks(hash FileID, ids []ChunkID) ([]Chunk, error) GetChunkIDsInStorage(hash FileID) ([]ChunkID, error) GetFileData(hash FileID) ([]byte, error) DeleteData(hash FileID) error }
func NewP2PStorage ¶
func NewP2PStorage() LocalStorage
type LocalStorageConfig ¶
type LocalStorageConfig struct {
ChunkSize int
}
type P2PFile ¶
P2PFile: Represent a P2PFile with all basic file infos.
- Hash: unique ID for the file based on file content
- state: FileState representing if the file is complete, updated or unchanged.
- Data: File content formed with chunks' data. Used to avoid excess data merging when requesting data.
- Chunks: All stored Chunks accesible by ChunkID.
func (*P2PFile) DeleteData ¶
func (f *P2PFile) DeleteData()
DeleteData: Delete file Data to free ressources
func (P2PFile) GetChunksIDs ¶
GetChunksIDs: Return all ChunkID's in a P2PFile.
func (*P2PFile) GetData ¶
GetData: Return stored data in a P2PFile. if the file is completed or unchanged since last call to GetData, directly return stored data. otherwise (FileState = FSUpdated), call UpdateData to reform data from received Chunk.
func (P2PFile) GetRequestedChunks ¶
type P2PFileStorage ¶
type P2PRemoteStorage ¶
type P2PRemoteStorage map[string]P2PFileStorage
func NewP2PRemoteStorage ¶
func NewP2PRemoteStorage() *P2PRemoteStorage
func (P2PRemoteStorage) AddFileChunksForPeer ¶
func (P2PRemoteStorage) GetFileSize ¶
func (s P2PRemoteStorage) GetFileSize(hash FileID) (int, error)
func (P2PRemoteStorage) GetPeersFileChunks ¶
func (s P2PRemoteStorage) GetPeersFileChunks(hash FileID) (map[PeerID][]ChunkID, error)
type P2PStorage ¶
type P2PStorage struct { // Map in not thread safe by design, so we have to use a mutex sync.Mutex Config LocalStorageConfig LocalFiles map[string]P2PFile }
func (*P2PStorage) AddFile ¶
func (s *P2PStorage) AddFile(fileData []byte) (FileID, error)
AddFile Add a file to local storage. Return the hashed file when successfull
func (*P2PStorage) AddReceivedFileChunks ¶
func (s *P2PStorage) AddReceivedFileChunks(hash FileID, chunks []Chunk) error
AddFile Add a file to local storage. Return the hashed file when successfull
func (*P2PStorage) DeleteData ¶
func (s *P2PStorage) DeleteData(hash FileID) error
func (*P2PStorage) GetChunkIDsInStorage ¶
func (s *P2PStorage) GetChunkIDsInStorage(hash FileID) ([]ChunkID, error)
func (*P2PStorage) GetFileData ¶
func (s *P2PStorage) GetFileData(hash FileID) ([]byte, error)
GetChunkIDsInStorage Search for requested chunk with file Hash
func (*P2PStorage) GetRequestedChunks ¶
func (s *P2PStorage) GetRequestedChunks(hash FileID, ids []ChunkID) ([]Chunk, error)
GetChunkIDsInStorage Search for requested chunk with file Hash