122 lines
3.2 KiB
Go
Raw Permalink Normal View History

2025-12-24 16:44:53 +04:00
package storage
2025-10-03 14:28:14 +02:00
/*
#include "bridge.h"
2025-10-07 08:34:44 +02:00
#include <stdlib.h>
2025-10-03 14:28:14 +02:00
2025-12-24 16:44:53 +04:00
static int cGoStorageDebug(void* storageCtx, void* resp) {
return storage_debug(storageCtx, (StorageCallback) callback, resp);
2025-10-03 14:28:14 +02:00
}
2025-10-07 08:34:44 +02:00
2025-12-24 16:44:53 +04:00
static int cGoStorageLogLevel(void* storageCtx, char* logLevel, void* resp) {
return storage_log_level(storageCtx, logLevel, (StorageCallback) callback, resp);
2025-10-07 08:34:44 +02:00
}
2025-10-07 15:15:21 +02:00
2025-12-24 16:44:53 +04:00
static int cGoStoragePeerDebug(void* storageCtx, char* peerId, void* resp) {
return storage_peer_debug(storageCtx, peerId, (StorageCallback) callback, resp);
2025-10-07 15:15:21 +02:00
}
2025-10-03 14:28:14 +02:00
*/
import "C"
2025-10-07 08:34:44 +02:00
import (
"encoding/json"
"unsafe"
)
2025-10-03 14:28:14 +02:00
type Node struct {
NodeId string `json:"nodeId"`
PeerId string `json:"peerId"`
Record string `json:"record"`
Address *string `json:"address"`
Seen bool `json:"seen"`
}
type RoutingTable struct {
LocalNode Node `json:"localNode"`
Nodes []Node `json:"nodes"`
}
type DebugInfo struct {
// Peer ID
ID string `json:"id"`
// Peer info addresses
2025-12-24 16:44:53 +04:00
// Specified with `ListenAddresses` in `StorageConfig`
Addrs []string `json:"addrs"`
Spr string `json:"spr"`
2025-10-03 14:28:14 +02:00
AnnounceAddresses []string `json:"announceAddresses"`
PeersTable RoutingTable `json:"table"`
}
2025-10-07 15:15:21 +02:00
type PeerRecord struct {
PeerId string `json:"peerId"`
SeqNo int `json:"seqNo"`
Addresses []string `json:"addresses,omitempty"`
}
2025-12-24 16:44:53 +04:00
// Debug retrieves debugging information from the Logos Storage node.
func (node StorageNode) Debug() (DebugInfo, error) {
2025-10-03 14:28:14 +02:00
var info DebugInfo
bridge := newBridgeCtx()
defer bridge.free()
2025-12-24 16:44:53 +04:00
if C.cGoStorageDebug(node.ctx, bridge.resp) != C.RET_OK {
return info, bridge.callError("cGoStorageDebug")
2025-10-03 14:28:14 +02:00
}
value, err := bridge.wait()
if err != nil {
return info, err
}
err = json.Unmarshal([]byte(value), &info)
return info, err
}
2025-10-07 08:34:44 +02:00
// UpdateLogLevel updates Chronicles runtime logging configuration.
// You can pass a plain level: TRACE, DEBUG, INFO, NOTICE, WARN, ERROR, FATAL.
// The default level is TRACE.
// You can also use Chronicles topic directives. So for example if you want
2025-12-24 16:44:53 +04:00
// to update the general level to INFO but want to see TRACE logs for the libstorage
// topic, you can pass "INFO,libstorage:TRACE".
func (node StorageNode) UpdateLogLevel(logLevel string) error {
2025-10-07 08:34:44 +02:00
bridge := newBridgeCtx()
defer bridge.free()
var cLogLevel = C.CString(string(logLevel))
defer C.free(unsafe.Pointer(cLogLevel))
2025-12-24 16:44:53 +04:00
if C.cGoStorageLogLevel(node.ctx, cLogLevel, bridge.resp) != C.RET_OK {
return bridge.callError("cGoStorageLogLevel")
2025-10-07 08:34:44 +02:00
}
_, err := bridge.wait()
return err
}
2025-10-07 15:15:21 +02:00
2025-12-24 16:44:53 +04:00
// StoragePeerDebug retrieves the peer record for a given peer ID.
// This function is available only if the flag
2025-12-24 16:44:53 +04:00
// -d:storage_enable_api_debug_peers=true was set at build time.
func (node StorageNode) StoragePeerDebug(peerId string) (PeerRecord, error) {
2025-10-07 15:15:21 +02:00
var record PeerRecord
bridge := newBridgeCtx()
defer bridge.free()
var cPeerId = C.CString(peerId)
defer C.free(unsafe.Pointer(cPeerId))
2025-12-24 16:44:53 +04:00
if C.cGoStoragePeerDebug(node.ctx, cPeerId, bridge.resp) != C.RET_OK {
return record, bridge.callError("cGoStoragePeerDebug")
2025-10-07 15:15:21 +02:00
}
value, err := bridge.wait()
if err != nil {
return record, err
}
err = json.Unmarshal([]byte(value), &record)
return record, err
}