network

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 6, 2024 License: MIT Imports: 16 Imported by: 0

README

Network

Server Structure:

HTTP/JSON-RPC server using Gorilla Mux Configurable TLS support Timeout and request size limits Graceful shutdown support

API Endpoints:

Transaction submission and status Chain state queries Validator registration and status Bridge operations and asset management

Request Handling:

Standardized JSON-RPC response format Comprehensive error handling Input validation Response formatting

Features:

Middleware support for authentication and logging TLS configuration Request rate limiting capability Status code handling

Key endpoints include:

Transaction Management:

/tx/submit - Submit new transactions /tx/status/{hash} - Check transaction status

Chain State:

/chain/status - Get current chain status /chain/block/{height} - Get block by height

Validator Operations:

/validator/status - Get validator status /validator/register - Register new validator

Bridge Operations:

/bridge/assets - Query registered assets /bridge/transfer - Initiate cross-chain transfer

Documentation

Overview

Package network implements the RPC server for the ATLYS protocol

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	ListenAddresses []string
	BootstrapPeers  []string
	MaxPeers        int
	MinPeers        int
}

type NodeStatus

type NodeStatus int
const (
	StatusDisconnected NodeStatus = iota
	StatusConnecting
	StatusConnected
	StatusActive
)

type P2PNetwork

type P2PNetwork struct {
	// contains filtered or unexported fields
}

func NewP2PNetwork

func NewP2PNetwork(cfg *Config) (*P2PNetwork, error)

func (*P2PNetwork) Broadcast

func (n *P2PNetwork) Broadcast(protocolID protocol.ID, msg []byte) error

func (*P2PNetwork) GetPeerCount

func (n *P2PNetwork) GetPeerCount() int

func (*P2PNetwork) GetValidatorCount

func (n *P2PNetwork) GetValidatorCount() int

func (*P2PNetwork) IsValidator

func (n *P2PNetwork) IsValidator(peerID peer.ID) bool

func (*P2PNetwork) RegisterProtocol

func (n *P2PNetwork) RegisterProtocol(id protocol.ID, handler ProtocolHandler)

func (*P2PNetwork) Start

func (n *P2PNetwork) Start() error

func (*P2PNetwork) Stop

func (n *P2PNetwork) Stop() error

func (*P2PNetwork) UpdateValidatorStatus

func (n *P2PNetwork) UpdateValidatorStatus(peerID peer.ID, status NodeStatus)

type Protocol

type Protocol struct {
	ID      protocol.ID
	Handler ProtocolHandler
}

type ProtocolHandler

type ProtocolHandler interface {
	HandleMessage(ctx context.Context, msg []byte) error
}

type RPCConfig

type RPCConfig struct {
	ListenAddr     string
	ReadTimeout    time.Duration
	WriteTimeout   time.Duration
	MaxHeaderBytes int
	EnableTLS      bool
	CertFile       string
	KeyFile        string
}

RPCConfig contains configuration parameters for the RPC server

type RPCError

type RPCError struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data,omitempty"`
}

RPCError represents a JSON-RPC error

type RPCResponse

type RPCResponse struct {
	JSONRPC string      `json:"jsonrpc"`
	ID      interface{} `json:"id"`
	Result  interface{} `json:"result,omitempty"`
	Error   *RPCError   `json:"error,omitempty"`
}

RPCResponse represents a standardized JSON-RPC response

type RPCServer

type RPCServer struct {
	// contains filtered or unexported fields
}

RPCServer handles RPC requests for the ATLYS protocol

func NewRPCServer

func NewRPCServer(bridge *bridge.Bridge, validator *core.Validator, config *RPCConfig) *RPCServer

NewRPCServer creates a new instance of the RPC server

func (*RPCServer) Start

func (s *RPCServer) Start() error

Start initializes and starts the RPC server

func (*RPCServer) Stop

func (s *RPCServer) Stop(ctx context.Context) error

Stop gracefully shuts down the RPC server

type ValidatorNode

type ValidatorNode struct {
	ID       peer.ID
	Address  types.Address
	LastSeen time.Time
	Status   NodeStatus
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL