mirror of
https://github.com/logos-storage/logos-storage-go-bindings.git
synced 2026-01-02 13:33:10 +00:00
Add peerid and spr
This commit is contained in:
parent
1fffbfc2c9
commit
b93f5c8b82
@ -49,6 +49,10 @@ package codex
|
||||
static int cGoCodexSpr(void* codexCtx, void* resp) {
|
||||
return codex_spr(codexCtx, (CodexCallback) callback, resp);
|
||||
}
|
||||
|
||||
static int cGoCodexPeerId(void* codexCtx, void* resp) {
|
||||
return codex_peer_id(codexCtx, (CodexCallback) callback, resp);
|
||||
}
|
||||
*/
|
||||
import "C"
|
||||
import (
|
||||
@ -73,6 +77,8 @@ const (
|
||||
LevelDb RepoKind = "leveldb"
|
||||
)
|
||||
|
||||
type rawJSON = json.RawMessage
|
||||
|
||||
type CodexConfig struct {
|
||||
LogFormat LogFormat `json:"log-format,omitempty"`
|
||||
MetricsEnabled bool `json:"metrics,omitempty"`
|
||||
@ -82,7 +88,7 @@ type CodexConfig struct {
|
||||
Nat string `json:"nat,omitempty"`
|
||||
DiscoveryPort int `json:"disc-port,omitempty"`
|
||||
NetPrivKeyFile string `json:"net-privkey,omitempty"`
|
||||
BootstrapNodes []byte `json:"bootstrap-node,omitempty"`
|
||||
BootstrapNodes []string `json:"bootstrap-node,omitempty"`
|
||||
MaxPeers int `json:"max-peers,omitempty"`
|
||||
NumThreads int `json:"num-threads,omitempty"`
|
||||
AgentString string `json:"agent-string,omitempty"`
|
||||
@ -108,6 +114,9 @@ func CodexNew(config CodexConfig) (*CodexNode, error) {
|
||||
bridge := newBridgeCtx()
|
||||
defer bridge.free()
|
||||
|
||||
// transform BootstrapNodes into rawJSON
|
||||
// rawJSON(fmt.Sprintf(`["%s"]`, spr))
|
||||
|
||||
jsonConfig, err := json.Marshal(config)
|
||||
|
||||
if err != nil {
|
||||
@ -189,7 +198,6 @@ func (node CodexNode) Version() (string, error) {
|
||||
return bridge.wait()
|
||||
}
|
||||
|
||||
// Revision returns the revision of the Codex node.
|
||||
func (node CodexNode) Revision() (string, error) {
|
||||
bridge := newBridgeCtx()
|
||||
defer bridge.free()
|
||||
@ -212,3 +220,25 @@ func (node CodexNode) Repo() (string, error) {
|
||||
|
||||
return bridge.wait()
|
||||
}
|
||||
|
||||
func (node CodexNode) Spr() (string, error) {
|
||||
bridge := newBridgeCtx()
|
||||
defer bridge.free()
|
||||
|
||||
if C.cGoCodexSpr(node.ctx, bridge.resp) != C.RET_OK {
|
||||
return "", bridge.callError("cGoCodexSpr")
|
||||
}
|
||||
|
||||
return bridge.wait()
|
||||
}
|
||||
|
||||
func (node CodexNode) PeerId() (string, error) {
|
||||
bridge := newBridgeCtx()
|
||||
defer bridge.free()
|
||||
|
||||
if C.cGoCodexPeerId(node.ctx, bridge.resp) != C.RET_OK {
|
||||
return "", bridge.callError("cGoCodexPeerId")
|
||||
}
|
||||
|
||||
return bridge.wait()
|
||||
}
|
||||
|
||||
@ -4,8 +4,9 @@ import "testing"
|
||||
|
||||
func TestCodexVersion(t *testing.T) {
|
||||
node, err := CodexNew(CodexConfig{
|
||||
DataDir: t.TempDir(),
|
||||
LogFormat: LogFormatNoColors,
|
||||
DataDir: t.TempDir(),
|
||||
LogFormat: LogFormatNoColors,
|
||||
MetricsEnabled: false,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create Codex node: %v", err)
|
||||
@ -25,8 +26,9 @@ func TestCodexVersion(t *testing.T) {
|
||||
|
||||
func TestCodexRevision(t *testing.T) {
|
||||
node, err := CodexNew(CodexConfig{
|
||||
DataDir: t.TempDir(),
|
||||
LogFormat: LogFormatNoColors,
|
||||
DataDir: t.TempDir(),
|
||||
LogFormat: LogFormatNoColors,
|
||||
MetricsEnabled: false,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create Codex node: %v", err)
|
||||
@ -57,3 +59,31 @@ func TestCodexRepo(t *testing.T) {
|
||||
|
||||
t.Logf("Codex repo: %s", repo)
|
||||
}
|
||||
|
||||
func TestSpr(t *testing.T) {
|
||||
node := newCodexNode(t)
|
||||
|
||||
spr, err := node.Spr()
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to get Codex SPR: %v", err)
|
||||
}
|
||||
if spr == "" {
|
||||
t.Fatal("Codex SPR is empty")
|
||||
}
|
||||
|
||||
t.Logf("Codex SPR: %s", spr)
|
||||
}
|
||||
|
||||
func TestPeerId(t *testing.T) {
|
||||
node := newCodexNode(t)
|
||||
|
||||
peerId, err := node.PeerId()
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to get Codex PeerId: %v", err)
|
||||
}
|
||||
if peerId == "" {
|
||||
t.Fatal("Codex PeerId is empty")
|
||||
}
|
||||
|
||||
t.Logf("Codex PeerId: %s", peerId)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user