refactor(node): align remaining AX naming and examples
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
3733e61962
commit
1ee54add39
11 changed files with 44 additions and 57 deletions
|
|
@ -179,7 +179,7 @@ Auto-connect: if the target peer is not yet connected, `sendRequest` calls `tran
|
|||
|----------|-------|---------|
|
||||
| `IntentHandshake` | `0x01` | Connection establishment |
|
||||
| `IntentCompute` | `0x20` | Compute job request |
|
||||
| `IntentRehab` | `0x30` | Benevolent intervention (pause execution) |
|
||||
| `IntentPauseExecution` | `0x30` | Benevolent intervention (pause execution) |
|
||||
| `IntentCustom` | `0xFF` | Application-level sub-protocols |
|
||||
|
||||
**Sentinel errors**:
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ Dropped packets are logged at WARN level with the threat score, threshold, inten
|
|||
const (
|
||||
IntentHandshake byte = 0x01 // Connection establishment / hello
|
||||
IntentCompute byte = 0x20 // Compute job request
|
||||
IntentRehab byte = 0x30 // Benevolent intervention (pause execution)
|
||||
IntentPauseExecution byte = 0x30
|
||||
IntentCustom byte = 0xFF // Extended / application-level sub-protocols
|
||||
)
|
||||
```
|
||||
|
|
|
|||
|
|
@ -156,7 +156,7 @@ Reserved intent values:
|
|||
|----|----------|---------|
|
||||
| `0x01` | `IntentHandshake` | Connection establishment / hello |
|
||||
| `0x20` | `IntentCompute` | Compute job request |
|
||||
| `0x30` | `IntentRehab` | Benevolent intervention (pause execution) |
|
||||
| `0x30` | `IntentPauseExecution` | Benevolent intervention (pause execution) |
|
||||
| `0xFF` | `IntentCustom` | Extended / application-level sub-protocols |
|
||||
|
||||
## Threat Score
|
||||
|
|
|
|||
|
|
@ -13,13 +13,12 @@ import (
|
|||
// threshold := ThreatScoreThreshold
|
||||
const ThreatScoreThreshold uint16 = 50000
|
||||
|
||||
// Well-known intent identifiers. These correspond to the semantic tokens
|
||||
// carried in the UEPS IntentID header field (RFC-021).
|
||||
// intentID := IntentPauseExecution
|
||||
const (
|
||||
IntentHandshake byte = 0x01 // Connection establishment / hello
|
||||
IntentCompute byte = 0x20 // Compute job request
|
||||
IntentRehab byte = 0x30 // Benevolent intervention (pause execution)
|
||||
IntentCustom byte = 0xFF // Extended / application-level sub-protocols
|
||||
IntentHandshake byte = 0x01
|
||||
IntentCompute byte = 0x20
|
||||
IntentPauseExecution byte = 0x30
|
||||
IntentCustom byte = 0xFF
|
||||
)
|
||||
|
||||
// var handler IntentHandler = func(packet *ueps.ParsedPacket) error { return nil }
|
||||
|
|
|
|||
|
|
@ -136,7 +136,7 @@ func TestDispatcher_UnknownIntentDropped_Bad(t *testing.T) {
|
|||
func TestDispatcher_MultipleHandlersCorrectRouting_Good(t *testing.T) {
|
||||
d := NewDispatcher()
|
||||
|
||||
var handshakeCalled, computeCalled, rehabCalled, customCalled bool
|
||||
var handshakeCalled, computeCalled, pauseExecutionCalled, customCalled bool
|
||||
|
||||
d.RegisterHandler(IntentHandshake, func(pkt *ueps.ParsedPacket) error {
|
||||
handshakeCalled = true
|
||||
|
|
@ -146,8 +146,8 @@ func TestDispatcher_MultipleHandlersCorrectRouting_Good(t *testing.T) {
|
|||
computeCalled = true
|
||||
return nil
|
||||
})
|
||||
d.RegisterHandler(IntentRehab, func(pkt *ueps.ParsedPacket) error {
|
||||
rehabCalled = true
|
||||
d.RegisterHandler(IntentPauseExecution, func(pkt *ueps.ParsedPacket) error {
|
||||
pauseExecutionCalled = true
|
||||
return nil
|
||||
})
|
||||
d.RegisterHandler(IntentCustom, func(pkt *ueps.ParsedPacket) error {
|
||||
|
|
@ -162,7 +162,7 @@ func TestDispatcher_MultipleHandlersCorrectRouting_Good(t *testing.T) {
|
|||
}{
|
||||
{"handshake routes correctly", IntentHandshake, &handshakeCalled},
|
||||
{"compute routes correctly", IntentCompute, &computeCalled},
|
||||
{"rehab routes correctly", IntentRehab, &rehabCalled},
|
||||
{"pause execution routes correctly", IntentPauseExecution, &pauseExecutionCalled},
|
||||
{"custom routes correctly", IntentCustom, &customCalled},
|
||||
}
|
||||
|
||||
|
|
@ -171,7 +171,7 @@ func TestDispatcher_MultipleHandlersCorrectRouting_Good(t *testing.T) {
|
|||
// Reset all flags
|
||||
handshakeCalled = false
|
||||
computeCalled = false
|
||||
rehabCalled = false
|
||||
pauseExecutionCalled = false
|
||||
customCalled = false
|
||||
|
||||
pkt := makePacket(tt.intentID, 0, []byte("payload"))
|
||||
|
|
@ -341,6 +341,6 @@ func TestDispatcher_IntentConstants_Good(t *testing.T) {
|
|||
// Verify the well-known intent IDs match the spec (RFC-021).
|
||||
assert.Equal(t, byte(0x01), IntentHandshake)
|
||||
assert.Equal(t, byte(0x20), IntentCompute)
|
||||
assert.Equal(t, byte(0x30), IntentRehab)
|
||||
assert.Equal(t, byte(0x30), IntentPauseExecution)
|
||||
assert.Equal(t, byte(0xFF), IntentCustom)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -572,7 +572,7 @@ func TestIntegration_DispatcherWithRealUEPSPackets_Good(t *testing.T) {
|
|||
}{
|
||||
{IntentHandshake, "handshake", "hello"},
|
||||
{IntentCompute, "compute", `{"job":"123"}`},
|
||||
{IntentRehab, "rehab", "pause"},
|
||||
{IntentPauseExecution, "pause-execution", "pause"},
|
||||
{IntentCustom, "custom", "app-specific-data"},
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,25 +11,25 @@ import (
|
|||
core "dappco.re/go/core"
|
||||
)
|
||||
|
||||
// HeaderSize is the exact byte length of a serialised Levin header.
|
||||
// headerBytes := make([]byte, HeaderSize)
|
||||
const HeaderSize = 33
|
||||
|
||||
// Signature is the magic value that opens every Levin packet.
|
||||
// header.Signature = Signature
|
||||
const Signature uint64 = 0x0101010101012101
|
||||
|
||||
// MaxPayloadSize is the upper bound we accept for a single payload (100 MB).
|
||||
// header.PayloadSize <= MaxPayloadSize
|
||||
const MaxPayloadSize uint64 = 100 * 1024 * 1024
|
||||
|
||||
// Return-code constants carried in every Levin response.
|
||||
const (
|
||||
// returnCode := ReturnOK
|
||||
ReturnOK int32 = 0
|
||||
ReturnErrorConnection int32 = -1
|
||||
ReturnErrorFormat int32 = -7
|
||||
ReturnErrorSignature int32 = -13
|
||||
)
|
||||
|
||||
// Command IDs for the CryptoNote P2P layer.
|
||||
const (
|
||||
// commandID := CommandHandshake
|
||||
CommandHandshake uint32 = 1001
|
||||
CommandTimedSync uint32 = 1002
|
||||
CommandPing uint32 = 1003
|
||||
|
|
@ -41,8 +41,8 @@ const (
|
|||
CommandResponseChain uint32 = 2007
|
||||
)
|
||||
|
||||
// Sentinel errors returned by DecodeHeader.
|
||||
var (
|
||||
// err := ErrorBadSignature
|
||||
ErrorBadSignature = core.E("levin", "bad signature", nil)
|
||||
ErrorPayloadTooBig = core.E("levin", "payload exceeds maximum size", nil)
|
||||
)
|
||||
|
|
|
|||
|
|
@ -8,18 +8,14 @@ import (
|
|||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// Protocol version constants.
|
||||
const (
|
||||
// ProtocolVersion is the current protocol version.
|
||||
// version := ProtocolVersion
|
||||
ProtocolVersion = "1.0"
|
||||
// MinProtocolVersion is the minimum supported version.
|
||||
// minimumVersion := MinProtocolVersion
|
||||
MinProtocolVersion = "1.0"
|
||||
)
|
||||
|
||||
// SupportedProtocolVersions lists all protocol versions this node supports.
|
||||
// Used for version negotiation during handshake.
|
||||
//
|
||||
// versions := SupportedProtocolVersions
|
||||
// versions := SupportedProtocolVersions
|
||||
var SupportedProtocolVersions = []string{"1.0"}
|
||||
|
||||
// payload := RawMessage(`{"pool":"pool.example.com:3333"}`)
|
||||
|
|
@ -50,9 +46,7 @@ func IsProtocolVersionSupported(version string) bool {
|
|||
return slices.Contains(SupportedProtocolVersions, version)
|
||||
}
|
||||
|
||||
// MessageType defines the type of P2P message.
|
||||
//
|
||||
// messageType := MessagePing
|
||||
// messageType := MessagePing
|
||||
type MessageType string
|
||||
|
||||
const (
|
||||
|
|
@ -241,12 +235,12 @@ type ErrorPayload struct {
|
|||
Details string `json:"details,omitempty"`
|
||||
}
|
||||
|
||||
// Common error codes.
|
||||
const (
|
||||
ErrorCodeUnknown = 1000
|
||||
ErrorCodeInvalidMessage = 1001
|
||||
ErrorCodeUnauthorized = 1002
|
||||
ErrorCodeNotFound = 1003
|
||||
ErrorCodeUnknown = 1000
|
||||
ErrorCodeInvalidMessage = 1001
|
||||
ErrorCodeUnauthorized = 1002
|
||||
ErrorCodeNotFound = 1003
|
||||
// code := ErrorCodeOperationFailed
|
||||
ErrorCodeOperationFailed = 1004
|
||||
ErrorCodeTimeout = 1005
|
||||
)
|
||||
|
|
|
|||
|
|
@ -58,16 +58,12 @@ func (h *ResponseHandler) ParseResponse(resp *Message, expectedType MessageType,
|
|||
// handler := DefaultResponseHandler
|
||||
var DefaultResponseHandler = &ResponseHandler{}
|
||||
|
||||
// ValidateResponse is a convenience function using the default handler.
|
||||
//
|
||||
// err := ValidateResponse(message, MessageStats)
|
||||
// err := ValidateResponse(message, MessageStats)
|
||||
func ValidateResponse(resp *Message, expectedType MessageType) error {
|
||||
return DefaultResponseHandler.ValidateResponse(resp, expectedType)
|
||||
}
|
||||
|
||||
// ParseResponse is a convenience function using the default handler.
|
||||
//
|
||||
// err := ParseResponse(message, MessageStats, &stats)
|
||||
// err := ParseResponse(message, MessageStats, &stats)
|
||||
func ParseResponse(resp *Message, expectedType MessageType, target any) error {
|
||||
return DefaultResponseHandler.ParseResponse(resp, expectedType, target)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,10 +27,10 @@ var messageLogSampleCounter atomic.Int64
|
|||
// messageLogSampleInterval controls how often we log debug messages in hot paths (1 in N).
|
||||
const messageLogSampleInterval = 100
|
||||
|
||||
// DefaultMaxMessageSize is the default maximum message size (1MB)
|
||||
// limit := DefaultMaxMessageSize
|
||||
const DefaultMaxMessageSize int64 = 1 << 20 // 1MB
|
||||
|
||||
// agentUserAgentPrefix identifies this tool in request headers.
|
||||
// prefix := agentUserAgentPrefix
|
||||
const agentUserAgentPrefix = "agent-go-p2p"
|
||||
|
||||
const (
|
||||
|
|
@ -41,14 +41,14 @@ const (
|
|||
|
||||
// transportConfig := DefaultTransportConfig()
|
||||
type TransportConfig struct {
|
||||
ListenAddr string // ":9091" default
|
||||
WebSocketPath string // "/ws" - WebSocket endpoint path
|
||||
TLSCertPath string // Optional TLS for wss://
|
||||
TLSKeyPath string
|
||||
MaxConnections int // Maximum concurrent connections
|
||||
MaxMessageSize int64 // Maximum message size in bytes (0 = 1MB default)
|
||||
PingInterval time.Duration // WebSocket keepalive interval
|
||||
PongTimeout time.Duration // Timeout waiting for pong
|
||||
ListenAddr string // config.ListenAddr = ":9091"
|
||||
WebSocketPath string // config.WebSocketPath = "/ws"
|
||||
TLSCertPath string // config.TLSCertPath = "/srv/p2p/tls.crt"
|
||||
TLSKeyPath string // config.TLSKeyPath = "/srv/p2p/tls.key"
|
||||
MaxConnections int // config.MaxConnections = 100
|
||||
MaxMessageSize int64 // config.MaxMessageSize = 1 << 20
|
||||
PingInterval time.Duration // config.PingInterval = 30 * time.Second
|
||||
PongTimeout time.Duration // config.PongTimeout = 10 * time.Second
|
||||
}
|
||||
|
||||
// transportConfig := DefaultTransportConfig()
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ type Worker struct {
|
|||
minerManager MinerManager
|
||||
profileManager ProfileManager
|
||||
startedAt time.Time
|
||||
DeploymentDirectory string // Base directory for deployments (defaults to xdg.DataHome)
|
||||
DeploymentDirectory string // worker.DeploymentDirectory = "/srv/p2p/deployments"
|
||||
}
|
||||
|
||||
// worker := NewWorker(nodeManager, transport)
|
||||
|
|
@ -395,9 +395,7 @@ func (w *Worker) handleDeploy(peerConnection *PeerConnection, message *Message)
|
|||
}
|
||||
}
|
||||
|
||||
// RegisterOnTransport installs the worker message handler on the transport.
|
||||
//
|
||||
// worker.RegisterOnTransport()
|
||||
// worker.RegisterOnTransport()
|
||||
func (w *Worker) RegisterOnTransport() {
|
||||
w.transport.OnMessage(w.HandleMessage)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue