network

package
v6.2.12 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2026 License: GPL-3.0 Imports: 33 Imported by: 0

Documentation

Overview

Package network is a generated GoMock package.

Index

Constants

View Source
const MaxReprocessBufferSize = 1000000

MaxReprocessBufferSize is the maximum number of events for Nats resulting from a Reprocess

View Source
const (
	// ModuleName specifies the name of this module.
	ModuleName = "Network"
)

Variables

View Source
var ErrDIDNutsDisabled = errors.New("network operations not supported; did:nuts support not configured")

ErrDIDNutsDisabled is returned from certain API methods when the core.ServerConfig.DIDMethods does not contain "nuts"

Functions

This section is empty.

Types

type Config

type Config struct {
	// Socket address for gRPC to listen on
	GrpcAddr string `koanf:"grpcaddr"`
	// ConnectionTimeout specifies the timeout before an outbound connection attempt times out (in milliseconds).
	ConnectionTimeout int `koanf:"connectiontimeout"`
	// MaxBackoff specifies the maximum backoff for outbound connections
	MaxBackoff time.Duration `koanf:"maxbackoff"`
	// IdleTimeout specifies the period without any received message after which a connection to a peer is closed.
	// Peers send gossip and diagnostics messages at a fixed interval, so a silent connection is a dead one. Zero disables the check.
	IdleTimeout time.Duration `koanf:"idletimeout"`
	// Public address of this nodes other nodes can use to connect to this node.
	BootstrapNodes []string `koanf:"bootstrapnodes"`
	// Protocols is the list of network protocols to enable on the server. They are specified by version (v1, v2).
	Protocols []int `koanf:"protocols"`
	// EnableDiscovery tells the node to automatically connect to other nodes
	EnableDiscovery bool `koanf:"enablediscovery"`

	// NodeDID defines the DID of the organization that operates this node, typically a vendor for EPD software.
	// It is used to identify it on the network.
	NodeDID string `koanf:"nodedid"`

	// ProtocolV2 specifies config for protocol v2
	ProtocolV2 v2.Config `koanf:"v2"`
}

Config holds the config for Transactions

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns the default NetworkEngine configuration.

func TestNetworkConfig

func TestNetworkConfig() Config

TestNetworkConfig creates new network config with a test directory as data path.

func (Config) IsProtocolEnabled

func (c Config) IsProtocolEnabled(version int) bool

IsProtocolEnabled returns true if the protocol is enabled, otherwise false.

type EventType

type EventType string

EventType defines a type for specifying the kind of events that can be published/subscribed on the Network.

type MockTransactions

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

MockTransactions is a mock of Transactions interface.

func NewMockTransactions

func NewMockTransactions(ctrl *gomock.Controller) *MockTransactions

NewMockTransactions creates a new mock instance.

func (*MockTransactions) AddressBook

func (m *MockTransactions) AddressBook() []transport.Contact

AddressBook mocks base method.

func (*MockTransactions) CreateTransaction

func (m *MockTransactions) CreateTransaction(ctx context.Context, spec Template) (dag.Transaction, error)

CreateTransaction mocks base method.

func (*MockTransactions) Disabled

func (m *MockTransactions) Disabled() bool

Disabled mocks base method.

func (*MockTransactions) DiscoverServices

func (m *MockTransactions) DiscoverServices(updatedDID did.DID)

DiscoverServices mocks base method.

func (*MockTransactions) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockTransactions) GetTransaction

func (m *MockTransactions) GetTransaction(transactionRef hash.SHA256Hash) (dag.Transaction, error)

GetTransaction mocks base method.

func (*MockTransactions) GetTransactionPayload

func (m *MockTransactions) GetTransactionPayload(transactionRef hash.SHA256Hash) ([]byte, error)

GetTransactionPayload mocks base method.

func (*MockTransactions) ListTransactionsInRange

func (m *MockTransactions) ListTransactionsInRange(startInclusive, endExclusive uint32) ([]dag.Transaction, error)

ListTransactionsInRange mocks base method.

func (*MockTransactions) PeerDiagnostics

func (m *MockTransactions) PeerDiagnostics() map[transport.PeerID]transport.Diagnostics

PeerDiagnostics mocks base method.

func (*MockTransactions) Reprocess

func (m *MockTransactions) Reprocess(ctx context.Context, contentType string) (*ReprocessReport, error)

Reprocess mocks base method.

func (*MockTransactions) Subscribe

func (m *MockTransactions) Subscribe(name string, receiver dag.ReceiverFn, filters ...SubscriberOption) error

Subscribe mocks base method.

func (*MockTransactions) Subscribers

func (m *MockTransactions) Subscribers() []dag.Notifier

Subscribers mocks base method.

func (*MockTransactions) WithPersistency

func (m *MockTransactions) WithPersistency() SubscriberOption

WithPersistency mocks base method.

type MockTransactionsMockRecorder

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

MockTransactionsMockRecorder is the mock recorder for MockTransactions.

func (*MockTransactionsMockRecorder) AddressBook

func (mr *MockTransactionsMockRecorder) AddressBook() *gomock.Call

AddressBook indicates an expected call of AddressBook.

func (*MockTransactionsMockRecorder) CreateTransaction

func (mr *MockTransactionsMockRecorder) CreateTransaction(ctx, spec any) *gomock.Call

CreateTransaction indicates an expected call of CreateTransaction.

func (*MockTransactionsMockRecorder) Disabled

func (mr *MockTransactionsMockRecorder) Disabled() *gomock.Call

Disabled indicates an expected call of Disabled.

func (*MockTransactionsMockRecorder) DiscoverServices

func (mr *MockTransactionsMockRecorder) DiscoverServices(updatedDID any) *gomock.Call

DiscoverServices indicates an expected call of DiscoverServices.

func (*MockTransactionsMockRecorder) GetTransaction

func (mr *MockTransactionsMockRecorder) GetTransaction(transactionRef any) *gomock.Call

GetTransaction indicates an expected call of GetTransaction.

func (*MockTransactionsMockRecorder) GetTransactionPayload

func (mr *MockTransactionsMockRecorder) GetTransactionPayload(transactionRef any) *gomock.Call

GetTransactionPayload indicates an expected call of GetTransactionPayload.

func (*MockTransactionsMockRecorder) ListTransactionsInRange

func (mr *MockTransactionsMockRecorder) ListTransactionsInRange(startInclusive, endExclusive any) *gomock.Call

ListTransactionsInRange indicates an expected call of ListTransactionsInRange.

func (*MockTransactionsMockRecorder) PeerDiagnostics

func (mr *MockTransactionsMockRecorder) PeerDiagnostics() *gomock.Call

PeerDiagnostics indicates an expected call of PeerDiagnostics.

func (*MockTransactionsMockRecorder) Reprocess

func (mr *MockTransactionsMockRecorder) Reprocess(ctx, contentType any) *gomock.Call

Reprocess indicates an expected call of Reprocess.

func (*MockTransactionsMockRecorder) Subscribe

func (mr *MockTransactionsMockRecorder) Subscribe(name, receiver any, filters ...any) *gomock.Call

Subscribe indicates an expected call of Subscribe.

func (*MockTransactionsMockRecorder) Subscribers

func (mr *MockTransactionsMockRecorder) Subscribers() *gomock.Call

Subscribers indicates an expected call of Subscribers.

func (*MockTransactionsMockRecorder) WithPersistency

func (mr *MockTransactionsMockRecorder) WithPersistency() *gomock.Call

WithPersistency indicates an expected call of WithPersistency.

type Network

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

Network implements Transactions interface and Engine functions.

func NewNetworkInstance

func NewNetworkInstance(
	config Config,
	store didstore.Store,
	keyStore crypto.KeyStore,
	eventPublisher events.Event,
	storeProvider storage.Provider,
	pkiValidator pki.Validator,
) *Network

NewNetworkInstance creates a new Network engine instance.

func NewTestNetworkInstance

func NewTestNetworkInstance(t *testing.T) *Network

NewTestNetworkInstance creates a new Transactions instance that writes it data to a test directory.

func (*Network) AddressBook

func (n *Network) AddressBook() []transport.Contact

func (*Network) CheckHealth

func (n *Network) CheckHealth() map[string]core.Health

CheckHealth performs health checks for the network engine.

func (*Network) CleanupSubscriberEvents

func (n *Network) CleanupSubscriberEvents(subscriberName, errorPrefix string) error

func (*Network) Config

func (n *Network) Config() interface{}

Config returns a pointer to the actual config of the module.

func (*Network) Configure

func (n *Network) Configure(config core.ServerConfig) error

Configure configures the Network subsystem

func (*Network) CreateTransaction

func (n *Network) CreateTransaction(ctx context.Context, template Template) (dag.Transaction, error)

CreateTransaction creates a new transaction from the given template.

func (*Network) Diagnostics

func (n *Network) Diagnostics() []core.DiagnosticResult

Diagnostics collects and returns diagnostics for the Network engine.

func (*Network) Disabled

func (n *Network) Disabled() bool

func (*Network) DiscoverServices

func (n *Network) DiscoverServices(updatedDID did.DID)

func (*Network) GetTransaction

func (n *Network) GetTransaction(transactionRef hash.SHA256Hash) (dag.Transaction, error)

GetTransaction retrieves the transaction for the given reference. If the transaction is not known, an error is returned.

func (*Network) GetTransactionPayload

func (n *Network) GetTransactionPayload(transactionRef hash.SHA256Hash) ([]byte, error)

GetTransactionPayload retrieves the transaction Payload for the given transaction. If the transaction or Payload is not found nil is returned.

func (*Network) ListTransactionsInRange

func (n *Network) ListTransactionsInRange(startInclusive uint32, endExclusive uint32) ([]dag.Transaction, error)

ListTransactionsInRange returns all transactions known to this Network instance with lamport clock value between startInclusive and endExclusive.

func (*Network) Migrate

func (n *Network) Migrate() error

func (*Network) Name

func (n *Network) Name() string

Name returns the module name.

func (*Network) PeerDiagnostics

func (n *Network) PeerDiagnostics() map[transport.PeerID]transport.Diagnostics

PeerDiagnostics returns a map containing diagnostic information of the node's peers. The key contains the remote peer's ID.

func (*Network) Reprocess

func (n *Network) Reprocess(ctx context.Context, contentType string) (*ReprocessReport, error)

func (*Network) Shutdown

func (n *Network) Shutdown() error

Shutdown cleans up any leftover go routines

func (*Network) Start

func (n *Network) Start() error

Start initiates the Network subsystem

func (*Network) Subscribe

func (n *Network) Subscribe(name string, subscriber dag.ReceiverFn, options ...SubscriberOption) error

Subscribe registers a receiverFn with specific options. The receiver is called when a transaction is added to the DAG. It's only called if the given dag.NotificationFilter's match.

func (*Network) Subscribers

func (n *Network) Subscribers() []dag.Notifier

func (*Network) WithPersistency

func (n *Network) WithPersistency() SubscriberOption

WithPersistency creates the SubscriberOption that creates the NotifierOption for persistency with the correct DAG KVStore

type Receiver

type Receiver func(transaction dag.Transaction, payload []byte) error

Receiver defines a callback function for processing transactions/payloads received by the DAG.

type ReprocessReport

type ReprocessReport struct {
}

ReprocessReport describes the reprocess exection.

type SubscriberOption

type SubscriberOption func() dag.NotifierOption

SubscriberOption creates a dag.NotifierOption

func WithSelectionFilter

func WithSelectionFilter(filter dag.NotificationFilter) SubscriberOption

WithSelectionFilter creates a SubscriberOption that creates a dag.NotifierOption with the given filter

type Template

type Template struct {
	KID             string
	Payload         []byte
	PublicKey       crypto.PublicKey
	Type            string
	Timestamp       time.Time
	AdditionalPrevs []hash.SHA256Hash
	Participants    dag.PAL
}

Template is used to build a spec for new transactions.

func TransactionTemplate

func TransactionTemplate(payloadType string, payload []byte, kid string) Template

TransactionTemplate creates a new Template with the given required properties.

func (Template) WithAdditionalPrevs

func (t Template) WithAdditionalPrevs(additionalPrevs []hash.SHA256Hash) Template

WithAdditionalPrevs specifies additional `prev` hashes, which are added to the set of prevs of the new transaction (current HEADs of the DAG). This is used to update entities that are mutable. By referring to the previous transaction of an entity, conflicts through parallel updates can be detected.

func (Template) WithAttachKey

func (t Template) WithAttachKey(key crypto.PublicKey) Template

WithAttachKey specifies that the signing key must be attached to the transaction, because it wasn't published before.

func (Template) WithPrivate

func (t Template) WithPrivate(participants []did.DID) Template

WithPrivate specifies that the transaction is private, and should only be readable by the given Participants.

func (Template) WithTimestamp

func (t Template) WithTimestamp(timestamp time.Time) Template

WithTimestamp specifies a custom signing time for the transaction. Otherwise, time.Now() is used.

type Transactions

type Transactions interface {
	// Subscribe registers a receiver for the specified transaction type.
	// A filter can be passed as option with the WithSelectionFilter function.
	// The events for the receiver can be made persistent by passing the network.WithPersistency() option.
	Subscribe(name string, receiver dag.ReceiverFn, filters ...SubscriberOption) error
	// Subscribers returns the list of notifiers on the DAG that emit events to subscribers.
	Subscribers() []dag.Notifier
	// GetTransactionPayload retrieves the transaction Payload for the given transaction.
	// If the transaction or Payload is not found, dag.ErrPayloadNotFound is returned.
	GetTransactionPayload(transactionRef hash.SHA256Hash) ([]byte, error)
	// GetTransaction retrieves the transaction for the given reference.
	// If the transaction is not found, a dag.ErrTransactionNotFound is returned.
	GetTransaction(transactionRef hash.SHA256Hash) (dag.Transaction, error)
	// CreateTransaction creates a new transaction according to the given spec.
	CreateTransaction(ctx context.Context, spec Template) (dag.Transaction, error)
	// ListTransactionsInRange returns all transactions known to this Network instance with lamport clock value between startInclusive and endExclusive.
	// endExclusive must be larger than startInclusive.
	ListTransactionsInRange(startInclusive uint32, endExclusive uint32) ([]dag.Transaction, error)
	// PeerDiagnostics returns a map containing diagnostic information of the node's peers. The key contains the remote peer's ID.
	PeerDiagnostics() map[transport.PeerID]transport.Diagnostics
	// Reprocess walks the DAG and publishes all transactions matching the contentType via Nats
	Reprocess(ctx context.Context, contentType string) (*ReprocessReport, error)
	// WithPersistency returns a SubscriberOption for persistency. It allows the DAG KVStore to be used as persistent store for notifications.
	// The notifications will then have ACID properties
	WithPersistency() SubscriberOption
	// DiscoverServices should be called by the VDR to let the network know it has processed and verified a document (update) for the DID.
	DiscoverServices(updatedDID did.DID)
	// AddressBook returns the list of contacts in the address book.
	AddressBook() []transport.Contact
	// Disabled returns true if core.ServerConfig.DIDMethods does not contain 'nuts'
	Disabled() bool
}

Transactions is the interface that defines the API for creating, reading and subscribing to Nuts Network transactions.

Directories

Path Synopsis
api
v1
Package v1 provides primitives to interact with the openapi HTTP API.
Package v1 provides primitives to interact with the openapi HTTP API.
dag
Package dag is a generated GoMock package.
Package dag is a generated GoMock package.
Package transport is a generated GoMock package.
Package transport is a generated GoMock package.
grpc
Package grpc is a generated GoMock package.
Package grpc is a generated GoMock package.
v2
Package v2 is a generated GoMock package.
Package v2 is a generated GoMock package.
v2/gossip
Package gossip is a generated GoMock package.
Package gossip is a generated GoMock package.

Jump to

Keyboard shortcuts

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