huge changes that need more doucmenting

This commit is contained in:
2023-05-30 18:42:33 +01:00
parent 201a5441bb
commit d06a49eb28
88 changed files with 169 additions and 112 deletions

View File

@@ -1,5 +1,5 @@
/*
File Name: Blockchain Cache Global.go
File Username: Blockchain Cache Global.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner
*/

View File

@@ -1,5 +1,5 @@
/*
File Name: Blockchain User.go
File Username: Blockchain User.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner
*/

View File

@@ -1,5 +1,5 @@
/*
File Name: Bootstrap.go
File Username: Bootstrap.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner

View File

@@ -1,5 +1,5 @@
/*
File Name: Command Traverse.go
File Username: Command Traverse.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner
*/

View File

@@ -1,5 +1,5 @@
/*
File Name: Commands.go
File Username: Commands.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner
*/

View File

@@ -1,5 +1,5 @@
/*
File Name: Settings.go
File Username: Settings.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner
*/

View File

@@ -1,5 +1,5 @@
/*
File Name: Connection.go
File Username: Connection.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner
*/

View File

@@ -1,5 +1,5 @@
/*
File Name: DHT Store.go
File Username: DHT Store.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner
*/

View File

@@ -1,5 +1,5 @@
/*
File Name: Exit.go
File Username: Exit.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner
*/

View File

@@ -1,5 +1,5 @@
/*
File Name: File Formats.go
File Username: File Formats.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner

View File

@@ -1,5 +1,5 @@
/*
File Name: Filter.go
File Username: Filter.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner

View File

@@ -1,5 +1,5 @@
/*
File Name: Kademlia.go
File Username: Kademlia.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner
*/

View File

@@ -1,5 +1,5 @@
/*
File Name: Message Send.go
File Username: Message Send.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner
*/

View File

@@ -1,5 +1,5 @@
/*
File Name: Network Detection.go
File Username: Network Detection.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner
*/

View File

@@ -1,5 +1,5 @@
/*
File Name: Network IPv4 Broadcast.go
File Username: Network IPv4 Broadcast.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner

View File

@@ -1,5 +1,5 @@
/*
File Name: Network IPv6 Multicast.go
File Username: Network IPv6 Multicast.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner
@@ -63,7 +63,7 @@ func (network *Network) MulticastIPv6Join() (err error) {
joinMulticastGroup := func(iface *net.Interface) (err error) {
pc := ipv6.NewPacketConn(network.multicastSocket)
if err := pc.JoinGroup(iface, &net.UDPAddr{IP: network.multicastIP}); err != nil {
//LogError("MulticastIPv6Join", "join multicast group iface '%s' multicast IP '%s' listen on IP '%s' port '%d': %v\n", iface.Name, network.multicastIP.String(), network.address.IP.String(), ipv6MulticastPort, err)
//LogError("MulticastIPv6Join", "join multicast group iface '%s' multicast IP '%s' listen on IP '%s' port '%d': %v\n", iface.Username, network.multicastIP.String(), network.address.IP.String(), ipv6MulticastPort, err)
return err
}

View File

@@ -1,5 +1,5 @@
/*
File Name: Network Init.go
File Username: Network Init.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner

View File

@@ -1,5 +1,5 @@
/*
File Name: Network UPnP.go
File Username: Network UPnP.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner

View File

@@ -1,5 +1,5 @@
/*
File Name: Network.go
File Username: Network.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner
*/

View File

@@ -1,5 +1,5 @@
/*
File Name: Networks.go
File Username: Networks.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner
*/

View File

@@ -1,5 +1,5 @@
/*
File Name: Peer ID.go
File Username: Peer ID.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner
*/

View File

@@ -1,5 +1,5 @@
/*
File Name: Peernet.go
File Username: Peernet.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner
*/
@@ -19,7 +19,7 @@ import (
)
// Init initializes the client. If the config file does not exist or is empty, a default one will be created.
// The User Agent must be provided in the form "Application Name/1.0".
// The User Agent must be provided in the form "Application Username/1.0".
// The returned status is of type ExitX. Anything other than ExitSuccess indicates a fatal failure.
func Init(UserAgent string, ConfigFilename string, Filters *Filters, ConfigOut interface{}) (backend *Backend, status int, err error) {
if UserAgent == "" {

View File

@@ -1,5 +1,5 @@
/*
File Name: Ping.go
File Username: Ping.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner
*/

View File

@@ -1,5 +1,5 @@
/*
File Name: Transfer Block.go
File Username: Transfer Block.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner
*/

View File

@@ -1,5 +1,5 @@
/*
File Name: Transfer UDT.go
File Username: Transfer UDT.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner

View File

@@ -1,5 +1,5 @@
/*
File Name: Transfer Virtual Connection.go
File Username: Transfer Virtual Connection.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner

View File

@@ -1,5 +1,5 @@
/*
File Name: Warehouse.go
File Username: Warehouse.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner
*/

View File

@@ -1,5 +1,5 @@
/*
File Name: Block Record File.go
File Username: Block Record File.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner
@@ -48,6 +48,8 @@ type BlockRecordFile struct {
Size uint64 // Size of the file data
NodeID []byte // Node ID, owner of the file
Tags []BlockRecordFileTag // Tags provide additional metadata
ProfileImage []byte // ProfileImage of the user who uploaded the file
Username string // Username of the User who uploaded the file
}
// BlockRecordFileTag provides metadata about the file.

View File

@@ -1,5 +1,5 @@
/*
File Name: Block Record Profile.go
File Username: Block Record Profile.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner

View File

@@ -1,5 +1,5 @@
/*
File Name: Block Record.go
File Username: Block Record.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner

View File

@@ -1,5 +1,5 @@
/*
File Name: Block.go
File Username: Block.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner

View File

@@ -1,5 +1,5 @@
/*
File Name: Blockchain.go
File Username: Blockchain.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner

View File

@@ -1,5 +1,5 @@
/*
File Name: File Tag.go
File Username: File Tag.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner
@@ -16,7 +16,7 @@ import (
// List of defined file tags. Virtual tags are generated at runtime and are read-only. They cannot be stored on the blockchain.
const (
TagName = 0 // Name of file.
TagName = 0 // Username of file.
TagFolder = 1 // Folder name.
TagDescription = 2 // Arbitrary description of the file. May contain hashtags.
TagDateShared = 3 // When the file was published on the blockchain. Virtual.

View File

@@ -1,5 +1,5 @@
/*
File Name: File.go
File Username: File.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner

View File

@@ -1,5 +1,5 @@
/*
File Name: Multi.go
File Username: Multi.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner

View File

@@ -1,5 +1,5 @@
/*
File Name: Profile Data.go
File Username: Profile Data.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner
*/

View File

@@ -1,5 +1,5 @@
/*
File Name: Profile.go
File Username: Profile.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner
*/

View File

@@ -167,7 +167,7 @@ func printFile(file BlockRecordFile) {
for _, tag := range file.Tags {
switch tag.Type {
case TagName:
fmt.Printf(" Name %s\n", tag.Text())
fmt.Printf(" Username %s\n", tag.Text())
case TagFolder:
fmt.Printf(" Folder %s\n", tag.Text())
case TagDescription:

View File

@@ -1,5 +1,5 @@
/*
File Name: DHT Lite.go
File Username: DHT Lite.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner

View File

@@ -1,5 +1,5 @@
/*
File Name: Hash Table.go
File Username: Hash Table.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner
*/

View File

@@ -1,5 +1,5 @@
/*
File Name: Information Request.go
File Username: Information Request.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner

View File

@@ -1,5 +1,5 @@
/*
File Name: Node.go
File Username: Node.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner
*/

View File

@@ -1,5 +1,5 @@
/*
File Name: Search Client.go
File Username: Search Client.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner

View File

@@ -1,5 +1,5 @@
/*
File Name: Fragment.go
File Username: Fragment.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner
*/

View File

@@ -1,5 +1,5 @@
/*
File Name: Merkle Tree.go
File Username: Merkle Tree.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner

View File

@@ -1,5 +1,5 @@
/*
File Name: Command.go
File Username: Command.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner
*/

View File

@@ -1,5 +1,5 @@
/*
File Name: File Transfer.go
File Username: File Transfer.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner

View File

@@ -1,5 +1,5 @@
/*
File Name: Hash.go
File Username: Hash.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner
*/

View File

@@ -1,5 +1,5 @@
/*
File Name: Message Encoding Announcement.go
File Username: Message Encoding Announcement.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner
*/

View File

@@ -1,5 +1,5 @@
/*
File Name: Message Encoding Get Block.go
File Username: Message Encoding Get Block.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner

View File

@@ -1,5 +1,5 @@
/*
File Name: Message Encoding Response.go
File Username: Message Encoding Response.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner
*/

View File

@@ -1,5 +1,5 @@
/*
File Name: Message Encoding Transfer.go
File Username: Message Encoding Transfer.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner

View File

@@ -1,5 +1,5 @@
/*
File Name: Message Encoding Traverse.go
File Username: Message Encoding Traverse.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner
*/

View File

@@ -1,5 +1,5 @@
/*
File Name: Message Encoding.go
File Username: Message Encoding.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner

View File

@@ -1,5 +1,5 @@
/*
File Name: Packet Encoding.go
File Username: Packet Encoding.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner

View File

@@ -1,5 +1,5 @@
/*
File Name: Packet Lite.go
File Username: Packet Lite.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner

View File

@@ -1,5 +1,5 @@
/*
File Name: Sequence.go
File Username: Sequence.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner

View File

@@ -1,5 +1,5 @@
/*
File Name: Sanitize.go
File Username: Sanitize.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner
*/

View File

@@ -1,5 +1,5 @@
/*
File Name: Normalizing.go
File name: Normalizing.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner

View File

@@ -1,5 +1,5 @@
/*
File Name: Search Index.go
File name: Search Index.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner
*/

View File

@@ -1,5 +1,5 @@
/*
File Name: Search Term.go
File name: Search Term.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner
*/

View File

@@ -1,5 +1,5 @@
/*
File Name: Text 2 Hash.go
File name: Text 2 Hash.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner
*/

View File

@@ -1,5 +1,5 @@
/*
File Name: Memory.go
File name: Memory.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner
*/

View File

@@ -1,5 +1,5 @@
/*
File Name: Pebble.go
File name: Pebble.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner

View File

@@ -1,5 +1,5 @@
/*
File Name: Pogreb.go
File Username: Pogreb.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner
*/

View File

@@ -1,5 +1,5 @@
/*
File Name: Store.go
File Username: Store.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner

View File

@@ -1,5 +1,5 @@
/*
File Name: Execute.go
File Username: Execute.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner
*/

View File

@@ -1,5 +1,5 @@
/*
File Name: Read Package.go
File Username: Read Package.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner
*/

View File

@@ -1,5 +1,5 @@
/*
File Name: UPnP.go
File Username: UPnP.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner
*/

View File

@@ -1,5 +1,5 @@
/*
File Name: Merkle.go
File Username: Merkle.go
Copyright: 2021 Peernet Foundation s.r.o.
Author: Peter Kleissner
*/

View File

@@ -1,5 +1,5 @@
/*
File Name: Store.go
File Username: Store.go
Copyright: 2021 Peernet Foundation s.r.o.
Author: Peter Kleissner
*/

View File

@@ -1,5 +1,5 @@
/*
File Name: Warehouse.go
File Username: Warehouse.go
Copyright: 2021 Peernet Foundation s.r.o.
Author: Peter Kleissner
*/
@@ -93,7 +93,7 @@ func (wh *Warehouse) IterateFiles(Callback func(Hash []byte, Size int64) (Contin
name1 := file.Name()
_, err = hex.DecodeString(name1)
// we are only looking for directories. Name has to be "XXXX" hex chars only.
// we are only looking for directories. Username has to be "XXXX" hex chars only.
if !file.IsDir() || len(name1) != 4 || err != nil {
continue
}
@@ -108,7 +108,7 @@ func (wh *Warehouse) IterateFiles(Callback func(Hash []byte, Size int64) (Contin
name2 := file2.Name()
_, err = hex.DecodeString(name2)
// we are only looking for directories. Name has to be "XXXX" hex chars only.
// we are only looking for directories. Username has to be "XXXX" hex chars only.
if !file2.IsDir() || len(name2) != 4 || err != nil {
continue
}

View File

@@ -1,5 +1,5 @@
/*
File Name: API.go
File Username: API.go
Copyright: 2021 Peernet Foundation s.r.o.
Author: Peter Kleissner
*/

View File

@@ -1,5 +1,5 @@
/*
File Name: Blockchain.go
File Username: Blockchain.go
Copyright: 2021 Peernet Foundation s.r.o.
Author: Peter Kleissner
*/

View File

@@ -1,5 +1,5 @@
/*
File Name: Download Transfer.go
File Username: Download Transfer.go
Copyright: 2021 Peernet Foundation s.r.o.
Author: Peter Kleissner

View File

@@ -1,5 +1,5 @@
/*
File Name: Download.go
File Username: Download.go
Copyright: 2021 Peernet Foundation s.r.o.
Author: Peter Kleissner
*/
@@ -78,6 +78,8 @@ func (api *WebapiInstance) apiDownloadStart(w http.ResponseWriter, r *http.Reque
info := &downloadInfo{backend: api.Backend, api: api, id: uuid.New(), created: time.Now(), hash: hash, nodeID: nodeID}
api.Backend.LogError("Download.DownloadStart", "output %v", downloadInfo{backend: api.Backend, api: api, id: uuid.New(), created: time.Now(), hash: hash, nodeID: nodeID})
// create the file immediately
if info.initDiskFile(filePath) != nil {
EncodeJSON(api.Backend, w, r, apiResponseDownloadStatus{APIStatus: DownloadResponseFileInvalid})
@@ -90,6 +92,8 @@ func (api *WebapiInstance) apiDownloadStart(w http.ResponseWriter, r *http.Reque
// start the download!
go info.Start()
api.Backend.LogError("Download.DownloadStart", "output %v", apiResponseDownloadStatus{APIStatus: DownloadResponseSuccess, ID: info.id, DownloadStatus: DownloadWaitMetadata})
EncodeJSON(api.Backend, w, r, apiResponseDownloadStatus{APIStatus: DownloadResponseSuccess, ID: info.id, DownloadStatus: DownloadWaitMetadata})
}
@@ -132,6 +136,8 @@ func (api *WebapiInstance) apiDownloadStatus(w http.ResponseWriter, r *http.Requ
info.RUnlock()
api.Backend.LogError("Download.DownloadStatus", "output %v", response)
EncodeJSON(api.Backend, w, r, response)
}

View File

@@ -1,5 +1,5 @@
/*
File Name: File Detection.go
File: File Detection.go
Copyright: 2021 Peernet Foundation s.r.o.
Author: Peter Kleissner
*/

View File

@@ -1,5 +1,5 @@
/*
File Name: File IO.go
File Username: File IO.go
Copyright: 2021 Peernet Foundation s.r.o.
Author: Peter Kleissner
*/

View File

@@ -1,5 +1,5 @@
/*
File Name: File.go
File Username: File.go
Copyright: 2021 Peernet Foundation s.r.o.
Author: Peter Kleissner
*/
@@ -8,6 +8,7 @@ package webapi
import (
"net/http"
"strconv"
"time"
"github.com/PeernetOfficial/core"
@@ -31,24 +32,25 @@ type apiFileMetadata struct {
// apiFile is the metadata of a file published on the blockchain
type apiFile struct {
ID uuid.UUID `json:"id"` // Unique ID.
Hash []byte `json:"hash"` // Blake3 hash of the file data
Type uint8 `json:"type"` // File Type. For example audio or document. See TypeX.
Format uint16 `json:"format"` // File Format. This is more granular, for example PDF or Word file. See FormatX.
Size uint64 `json:"size"` // Size of the file
Folder string `json:"folder"` // Folder, optional
Name string `json:"name"` // Name of the file
Description string `json:"description"` // Description. This is expected to be multiline and contain hashtags!
Date time.Time `json:"date"` // Date shared
NodeID []byte `json:"nodeid"` // Node ID, owner of the file. Read only.
Metadata []apiFileMetadata `json:"metadata"` // Additional metadata.
Profile apiBlockRecordProfile
ID uuid.UUID `json:"id"` // Unique ID.
Hash []byte `json:"hash"` // Blake3 hash of the file data
Type uint8 `json:"type"` // File Type. For example audio or document. See TypeX.
Format uint16 `json:"format"` // File Format. This is more granular, for example PDF or Word file. See FormatX.
Size uint64 `json:"size"` // Size of the file
Folder string `json:"folder"` // Folder, optional
Name string `json:"name"` // Name of the file
Description string `json:"description"` // Description. This is expected to be multiline and contain hashtags!
Date time.Time `json:"date"` // Date shared
NodeID []byte `json:"nodeid"` // Node ID, owner of the file. Read only.
Metadata []apiFileMetadata `json:"metadata"` // Additional metadata.
ProfilePicture []byte `json:"profilepicture"` // The Profile Picture of the user who uploaded the file
Username string `json:"username"` // Username of the user who uploaded the file
}
// --- conversion from core to API data ---
func blockRecordFileToAPI(input blockchain.BlockRecordFile) (output apiFile) {
output = apiFile{ID: input.ID, Hash: input.Hash, NodeID: input.NodeID, Type: input.Type, Format: input.Format, Size: input.Size, Metadata: []apiFileMetadata{}}
output = apiFile{ID: input.ID, Hash: input.Hash, NodeID: input.NodeID, Type: input.Type, Format: input.Format, Size: input.Size, ProfilePicture: input.ProfileImage, Username: input.Username, Metadata: []apiFileMetadata{}}
for _, tag := range input.Tags {
switch tag.Type {
@@ -193,16 +195,25 @@ func (api *WebapiInstance) apiBlockchainFileAdd(w http.ResponseWriter, r *http.R
/*
apiBlockchainFileList lists all files stored on the blockchain.
Request: GET /blockchain/file/list
Request: GET /blockchain/file/list?fileFormat=<file format>
Response: 200 with JSON structure apiBlockAddFiles
*/
func (api *WebapiInstance) apiBlockchainFileList(w http.ResponseWriter, r *http.Request) {
files, status := api.Backend.UserBlockchain.ListFiles()
r.ParseForm()
// filter based on file type
fileType, err := strconv.Atoi(r.Form.Get("fileFormat"))
var result apiBlockAddFiles
for _, file := range files {
result.Files = append(result.Files, blockRecordFileToAPI(file))
apiFile := blockRecordFileToAPI(file)
if apiFile.Format == uint16(fileType) {
result.Files = append(result.Files, apiFile)
} else if err != nil {
result.Files = append(result.Files, apiFile)
}
}
result.Status = status

View File

@@ -1,5 +1,5 @@
/*
File Name: GeoIP.go
File Username: GeoIP.go
Copyright: 2021 Peernet Foundation s.r.o.
Author: Peter Kleissner

View File

@@ -1,5 +1,5 @@
/*
File Name: HTTP Range.go
File Username: HTTP Range.go
Copyright: 2021 Peernet Foundation s.r.o.
Author: Peter Kleissner
*/

View File

@@ -1,5 +1,5 @@
/*
File Name: Profile.go
File Username: Profile.go
Copyright: 2021 Peernet Foundation s.r.o.
Author: Peter Kleissner
*/

View File

@@ -1,5 +1,5 @@
/*
File Name: Search Dispatch.go
File Username: Search Dispatch.go
Copyright: 2021 Peernet Foundation s.r.o.
Author: Peter Kleissner
*/

View File

@@ -1,5 +1,5 @@
/*
File Name: Search Job.go
File Username: Search Job.go
Copyright: 2021 Peernet Foundation s.r.o.
Author: Peter Kleissner
*/
@@ -257,7 +257,7 @@ func (job *SearchJob) isFileFiltered(file *apiFile) bool {
return true
}
// SortFiles sorts a list of files. It returns a sorted list. 0 = no sorting, 1 = Relevance ASC, 2 = Relevance DESC, 3 = Date ASC, 4 = Date DESC, 5 = Name ASC, 6 = Name DESC
// SortFiles sorts a list of files. It returns a sorted list. 0 = no sorting, 1 = Relevance ASC, 2 = Relevance DESC, 3 = Date ASC, 4 = Date DESC, 5 = Username ASC, 6 = Username DESC
func SortFiles(files []*apiFile, Sort int) (sorted []*apiFile) {
switch Sort {
case SortRelevanceAsc:

View File

@@ -1,5 +1,5 @@
/*
File Name: Search.go
File Username: Search.go
Copyright: 2021 Peernet Foundation s.r.o.
Author: Peter Kleissner
@@ -353,7 +353,7 @@ func (api *WebapiInstance) apiSearchStatistic(w http.ResponseWriter, r *http.Req
apiExplore returns recently shared files in Peernet. Results are returned in real-time. The file type is an optional filter. See TypeX.
Special type -2 = Binary, Compressed, Container, Executable. This special type includes everything except Documents, Video, Audio, Ebooks, Picture, Text.
Request: GET /explore?limit=[max records]&type=[file type]&offset=[offset]
Request: GET /explore?limit=[max records]&type=[file type]&offset=[offset]&node=[nodeID]
Result: 200 with JSON structure SearchResult. Check the field status.
*/
func (api *WebapiInstance) apiExplore(w http.ResponseWriter, r *http.Request) {
@@ -369,7 +369,14 @@ func (api *WebapiInstance) apiExplore(w http.ResponseWriter, r *http.Request) {
fileType = -1
}
result := api.ExploreHelper(fileType, limit, offset, []byte{}, false)
var result *SearchResult
NodeId, valid := DecodeBlake3Hash(r.Form.Get("node"))
if valid {
result = api.ExploreHelper(fileType, limit, offset, NodeId, true)
} else {
result = api.ExploreHelper(fileType, limit, offset, []byte{}, false)
}
EncodeJSON(api.Backend, w, r, result)
}

View File

@@ -1,5 +1,5 @@
/*
File Name: Shared Recent.go
File Username: Shared Recent.go
Copyright: 2021 Peernet Foundation s.r.o.
Author: Peter Kleissner
*/
@@ -18,7 +18,6 @@ func (api *WebapiInstance) queryRecentShared(backend *core.Backend, fileType int
if limitPeer == 0 {
limitPeer = 1
}
// Assign peer list as an empty array
var peerList []*core.PeerInfo
@@ -45,10 +44,37 @@ func (api *WebapiInstance) queryRecentShared(backend *core.Backend, fileType int
var filesFromPeer uint64
var ProfileImage []byte
var Name string
ProfileNameFound := false
ProfilePictureFound := false
// First iteration of the entire blockchain to search for the profile
// image and Username of the user
for blockN1 := peer.BlockchainHeight - 1; blockN1 > 0; blockN1-- {
blockDecoded, _, found, _ := backend.ReadBlock(peer.PublicKey, peer.BlockchainVersion, blockN1)
if !found {
continue
}
// Adding profile image and Username to the output
for raw := range blockDecoded.Block.RecordsRaw {
if blockDecoded.Block.RecordsRaw[raw].Type == blockchain.ProfilePicture && !ProfilePictureFound {
ProfileImage = blockDecoded.Block.RecordsRaw[raw].Data
ProfilePictureFound = true
}
if blockDecoded.Block.RecordsRaw[raw].Type == blockchain.ProfileName && !ProfileNameFound {
Name = string(blockDecoded.Block.RecordsRaw[raw].Data[:])
ProfileNameFound = true
}
}
}
// decode blocks from top down
blockLoop:
for blockN := peer.BlockchainHeight - 1; blockN > 0; blockN-- {
blockDecoded, _, found, _ := backend.ReadBlock(peer.PublicKey, peer.BlockchainVersion, blockN)
if !found {
continue
}
@@ -62,6 +88,11 @@ func (api *WebapiInstance) queryRecentShared(backend *core.Backend, fileType int
file.Tags = append(file.Tags, blockchain.TagFromText(blockchain.TagSharedByGeoIP, sharedByGeoIP))
}
// Add profile image
file.ProfileImage = ProfileImage
// Add profile name
file.Username = Name
// found a new file! append.
if filesFromPeer < limitPeer {
filesFromPeer++

View File

@@ -1,5 +1,5 @@
/*
File Name: Status.go
File Username: Status.go
Copyright: 2021 Peernet Foundation s.r.o.
Author: Peter Kleissner
*/

View File

@@ -1,5 +1,5 @@
/*
File Name: Warehouse.go
File Username: Warehouse.go
Copyright: 2021 Peernet Foundation s.r.o.
Author: Peter Kleissner
*/