relay

package
v0.0.0-...-c7b2f4b Latest Latest
Warning

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

Go to latest
Published: May 24, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseRequest

func ParseRequest(data []byte) (any, error)

ParseRequest parses a request from the client. The return value can be:

Publish
Subscribe

func ParseResponse

func ParseResponse(data []byte) (any, error)

ParseResponse parses a response from the server. The return value can be:

EventPublishResponse
RelayServerIdentifyResponse
SubscribeResponse
RelayServerNotice

func ShallowSleep

func ShallowSleep(ctx context.Context, d time.Duration, signalChan chan any)

Types

type ClientConnectionStatusCallback

type ClientConnectionStatusCallback func(ctx context.Context, cancelFunc context.CancelCauseFunc, client RelayClient, serverIdentity string, status bool)

ClientConnectionStatusCallback is a callback function that is called when the connection status of the client changes. The implementation note:

  1. The callback function is called in a goroutine.
  2. Use *cancelFunc* to notify the caller there is something wrong of the callback. The caller should handle it.
  3. cancelFunc can be nil.

type Event

type Event struct {
	Timestamp int64
	Offset    int64
	Type      int
	Data      []byte
}

type EventPublishRequest

type EventPublishRequest struct {
	RequestID string `json:"request_id,omitempty"`
	Type      int    `json:"type"`
	Data      []byte `json:"data"`
}

EventPublishRequest is a request from the client to publish an event to the relay server.

type EventPublishResponse

type EventPublishResponse struct {
	// RequestID is the request ID of the EventPublishRequest.
	RequestID string `json:"request_id,omitempty"`
	OK        bool   `json:"ok"`
	EventID   string `json:"event_id"`
	Reason    string `json:"reason,omitempty"`
}

type EventSink

type EventSink func(ctx context.Context, event Event) (string, error)

type EventSourcePullingRequest

type EventSourcePullingRequest struct {
	Offset int64
	Type   int
	Length int
}

type EventSourcePullingResponse

type EventSourcePullingResponse struct {
	Events    []Event
	MaxOffset int64
}

type EventType

type EventType int
const (
	BusinessUnit               EventType = 801
	BusinessUnitAuthentication EventType = 802

	X509Certificate               EventType = 901
	X509CertificateRevocationList EventType = 902

	FileBasedBillOfLading          EventType = 1001
	EncryptedFileBasedBillOfLading EventType = 1002
)

type NoStrClientSubscriptionFilter

type NoStrClientSubscriptionFilter struct {
	Since  *int64
	Until  *int64
	Offset *int64
}

type NostrClient

type NostrClient struct {
	io.Closer
	// contains filtered or unexported fields
}

func NewNostrClient

func NewNostrClient(opts ...NostrClientOption) *NostrClient

func (*NostrClient) Close

func (c *NostrClient) Close() error

func (*NostrClient) Publish

func (c *NostrClient) Publish(ctx context.Context, evtType int, data []byte) error

func (*NostrClient) Subscribe

func (c *NostrClient) Subscribe(ctx context.Context, offset int64) error

type NostrClientOption

type NostrClientOption func(s *NostrClient)

func NostrClientWithConnectionStatusCallback

func NostrClientWithConnectionStatusCallback(callback ClientConnectionStatusCallback) NostrClientOption

func NostrClientWithEventSink

func NostrClientWithEventSink(sink EventSink) NostrClientOption

func NostrClientWithServerURL

func NostrClientWithServerURL(serverUrl string) NostrClientOption

type NostrClientOutputMsg

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

type NostrClientStub

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

NostrClientStub is a presentation of a client connection to the relay server.

func (*NostrClientStub) Run

func (c *NostrClientStub) Run()

type NostrClientSubscription

type NostrClientSubscription struct {
	SubscribeID string
	Type        int
	Offset      int64
	CloseChan   chan any
}

type NostrServer

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

func NewNostrServer

func NewNostrServer(opts ...NostrServerOption) *NostrServer

func (*NostrServer) Close

func (s *NostrServer) Close() error

func (*NostrServer) ListenAndServe

func (s *NostrServer) ListenAndServe() error

func (*NostrServer) ServeHTTP

func (s *NostrServer) ServeHTTP(w http.ResponseWriter, r *http.Request)

type NostrServerOption

type NostrServerOption func(s *NostrServer)

func NostrServerAddress

func NostrServerAddress(address string) NostrServerOption

func NostrServerTLS

func NostrServerTLS(certFile, keyFile string) NostrServerOption

func NostrServerWithEventSink

func NostrServerWithEventSink(sink EventSink) NostrServerOption

func NostrServerWithEventSource

func NostrServerWithEventSource(source EventSource) NostrServerOption

func NostrServerWithIdentity

func NostrServerWithIdentity(identity string) NostrServerOption

type RelayClient

type RelayClient interface {
	io.Closer

	// Send sends a message to the relay server.
	Publish(ctx context.Context, evtType int, data []byte) error

	// Subscribe event.
	Subscribe(ctx context.Context, offset int64) error
}

type RelayServer

type RelayServer interface {
	io.Closer
	ListenAndServe() error
}

type RelayServerIdentifyResponse

type RelayServerIdentifyResponse struct {
	Identity string `json:"identify"`
}

type RelayServerNotice

type RelayServerNotice struct {
	Message string `json:"message"`
}

type Request

type Request struct {
	Publish   *EventPublishRequest `json:"publish,omitempty"`
	Subscribe *SubscribeRequest    `json:"subscribe,omitempty"`
}

Request is a request to the relay server.

type Response

type Response struct {
	RelayServerIdentifyResponse *RelayServerIdentifyResponse `json:"identify_response,omitempty"`
	SubscribeResponse           *SubscribeResponse           `json:"subscribe_response,omitempty"`
	EventPublishResponse        *EventPublishResponse        `json:"publish_response,omitempty"`
	Notice                      *RelayServerNotice           `json:"notice,omitempty"`
}

Response is a message from the relay server.

type SubscribeRequest

type SubscribeRequest struct {
	SubscribeID string `json:"subscribe_id,omitempty"`
	Type        int    `json:"type"`
	Offset      int64  `json:"offset"`
}

SubscribeRequest is a request from the client to subscribe an event from the relay server.

type SubscribeResponse

type SubscribeResponse struct {
	SubscribeID string `json:"subscribe_id,omitempty"`
	Event       *Event `json:"event,omitempty"`
	EOS         bool   `json:"eos"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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