Files
Igor Sirotin c3768ff3fc refactor: address review on the Node facades
Move the Messaging API back out of pkg/kernel: ffi.Handle becomes a
defined type in the internal package, so kernel can hand the context to
pkg/messaging through kernel.Handle without the kernel layer knowing the
tier exists, and without the type being nameable outside this module.

Split Discovery into DiscV5, PeerExchange and DNSDiscovery, group the
node's identity and health under Debug(), and give every facade a pointer
receiver. Drop the node name, the per-operation logging that duplicates
what the library already writes, and GetFreePortIfNeeded — port 0 already
means "let the OS pick".

Heavy kernel tests now mark themselves with requiresNode and skip under
-short, so the gate runs `go test -short ./...` instead of naming tests
in a regexp.
2026-08-25 00:46:13 +01:00

52 lines
1.2 KiB
Go

package kernel
import (
"context"
"encoding/json"
"fmt"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/logos-messaging/logos-delivery-go-bindings/internal/ffi"
"github.com/logos-messaging/logos-delivery-go-bindings/pkg/kernel/common"
)
// Store is a Node's store protocol surface. Take one with Node.Store.
type Store struct{ n *Node }
// Query runs a store query against a store peer and returns its response. A
// ctx without a deadline gets the package default of 30s.
func (s *Store) Query(
ctx context.Context, request *common.StoreQueryRequest, peerInfo peer.AddrInfo,
) (*common.StoreQueryResponse, error) {
if err := s.n.check(); err != nil {
return nil, err
}
if err := ctx.Err(); err != nil {
return nil, err
}
requestJSON, err := json.Marshal(request)
if err != nil {
return nil, err
}
addr, err := peerAddr(peerInfo)
if err != nil {
return nil, err
}
responseJSON, err := ffi.StoreQuery(
s.n.h, string(requestJSON), addr, timeoutMillis(ctx, requestTimeout),
)
if err != nil {
return nil, fmt.Errorf("kernel: store query: %w", err)
}
var response common.StoreQueryResponse
if err := json.Unmarshal([]byte(responseJSON), &response); err != nil {
return nil, err
}
return &response, nil
}