arpfuckery

package module
v0.0.0-...-4373b60 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2026 License: MIT Imports: 20 Imported by: 0

README

arpfuckery

arpfuckery is a small go experiment for moving data over a local network using an ARP-shaped distributed object store-like transport.

The repo contains a reusable arpfuckery package plus a CLI with a couple of demos:

  • chat - a terminal chat prototype over the transport
  • wormhole - send and receive files between machines on the same network

Documentation

Index

Constants

View Source
const (
	OptimisticBurstDisabled uint16 = 0
	OptimisticBurstAll      uint16 = ^uint16(0)
)
View Source
const (
	PacketTypeHave uint8 = iota
	PacketTypeWant
	PacketTypeFrag
)

Variables

This section is empty.

Functions

func FmtMetaKVs

func FmtMetaKVs(values map[string]string) []byte

func MarshalPacket

func MarshalPacket(p Packet) ([]byte, error)

func ParseMetaKVs

func ParseMetaKVs(data []byte) map[string]string

Types

type AdmissionPolicy

type AdmissionPolicy func(*HavePacket) bool

type Client

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

func NewClient

func NewClient(ifaceName string) (*Client, error)

func NewClientWithOpts

func NewClientWithOpts(ifaceName string, opts ClientOpts) (*Client, error)

func (*Client) CreateObject

func (c *Client) CreateObject(data, metadata []byte) (*Object, error)

func (*Client) GetObjectSnapshot

func (c *Client) GetObjectSnapshot(id ObjectID, includeData bool) (ObjectSnapshot, bool)

func (*Client) PinObject

func (c *Client) PinObject(id ObjectID) bool

func (*Client) Start

func (c *Client) Start(ctx context.Context)

func (*Client) Stop

func (c *Client) Stop()

func (*Client) SubscribeObject

func (c *Client) SubscribeObject(id ObjectID, buf int) (<-chan ObjectEvent, func())

func (*Client) SubscribeObjects

func (c *Client) SubscribeObjects(buf int) (<-chan *Object, func())

func (*Client) UnpinObject

func (c *Client) UnpinObject(id ObjectID) bool

type ClientOpts

type ClientOpts struct {
	ObjectCapacity               int
	SweepInterval                time.Duration
	ReannounceInterval           time.Duration
	DefaultReceivedIncompleteTTL time.Duration
	DefaultReceivedCompleteTTL   time.Duration
	DefaultCreatedCompleteTTL    time.Duration
	WantRetryDelay               time.Duration
	WantMaxRetries               int
	QueueHaveCapacity            int
	QueueWantCapacity            int
	QueueOwnedCapacity           int
	QueueReplicaCapacity         int
	SeenFragCapacity             int
	SeenFragTTL                  time.Duration
	ReplicaDelay                 time.Duration
	ReplicaJitter                time.Duration
	OptimisticBurstMaxSize       uint64
	OptimisticBurstFrags         uint16
	AdmissionPolicy              AdmissionPolicy
	AutoPinOwned                 bool
	AutoPinReceived              bool
	Logger                       *log.Logger
}

func DefaultClientOpts

func DefaultClientOpts() ClientOpts

type FragPacket

type FragPacket struct {
	ObjectID  ObjectID // half a sha256 hash
	FragIndex uint16   // index of the fragment
	Payload   []byte   // arbitrary payload

	// not marshaled
	SourceMAC net.HardwareAddr
}

func (*FragPacket) MarshalBinary

func (p *FragPacket) MarshalBinary() ([]byte, error)

func (*FragPacket) Source

func (p *FragPacket) Source() net.HardwareAddr

func (*FragPacket) UnmarshalBinary

func (p *FragPacket) UnmarshalBinary(data []byte) error

type FragmentRef

type FragmentRef struct {
	ObjectID  ObjectID
	FragIndex uint16
}

type HavePacket

type HavePacket struct {
	ObjectID   ObjectID   // half a sha256 hash
	ObjectSize uint64     // it would be very funny to use the full extent of this
	ObjectHash ObjectHash // sha256 hash of the entire object
	FragCount  uint16     // number of fragments in the object
	Metadata   []byte     // arbitrary metadata idk what this will look like, can't be fragmented...

	// not marshaled
	SourceMAC net.HardwareAddr
}

func (*HavePacket) MarshalBinary

func (p *HavePacket) MarshalBinary() ([]byte, error)

func (*HavePacket) Source

func (p *HavePacket) Source() net.HardwareAddr

func (*HavePacket) UnmarshalBinary

func (p *HavePacket) UnmarshalBinary(data []byte) error

type Object

type Object struct {
	ID        ObjectID
	Size      uint64
	Hash      ObjectHash
	FragCount uint16
	Metadata  []byte

	Created     time.Time
	CompletedAt time.Time
	Expires     time.Time
	LastHave    time.Time
	LastRetry   time.Time
	NextWant    time.Time
	Source      net.HardwareAddr
	Retries     int
	Owned       bool
	Pinned      bool
	Complete    bool

	Fragments map[uint16][]byte
	Data      []byte
}

func (*Object) HavePacket

func (o *Object) HavePacket() *HavePacket

func (*Object) Snapshot

func (o *Object) Snapshot(includeData bool) ObjectSnapshot

type ObjectEvent

type ObjectEvent struct {
	Kind   ObjectEventKind
	Object ObjectSnapshot
}

type ObjectEventKind

type ObjectEventKind string
const (
	ObjectEventDiscovered ObjectEventKind = "discovered"
	ObjectEventProgress   ObjectEventKind = "progress"
	ObjectEventComplete   ObjectEventKind = "complete"
)

type ObjectHash

type ObjectHash [32]byte

func ObjectHashBytes

func ObjectHashBytes(data []byte) ObjectHash

func (ObjectHash) String

func (h ObjectHash) String() string

type ObjectID

type ObjectID [16]byte

func ObjectIDFromHash

func ObjectIDFromHash(hash ObjectHash) ObjectID

func ParseObjectID

func ParseObjectID(raw string) (ObjectID, error)

func (ObjectID) String

func (id ObjectID) String() string

type ObjectSnapshot

type ObjectSnapshot struct {
	ID            ObjectID
	Size          uint64
	Hash          ObjectHash
	FragCount     uint16
	Metadata      []byte
	Created       time.Time
	CompletedAt   time.Time
	Expires       time.Time
	LastHave      time.Time
	LastRetry     time.Time
	NextWant      time.Time
	Source        net.HardwareAddr
	Retries       int
	Owned         bool
	Pinned        bool
	Complete      bool
	ReceivedFrags uint16
	ReceivedBytes uint64
	Data          []byte
}

type Packet

type Packet interface {
	MarshalBinary() ([]byte, error)
	Source() net.HardwareAddr
}

func Unmarshal

func Unmarshal(cap gopacket.Packet) (Packet, bool, error)

func UnmarshalPacket

func UnmarshalPacket(data []byte) (Packet, error)

type WantPacket

type WantPacket struct {
	ObjectID  ObjectID // half a sha256 hash
	FragCount uint16   // number of fragments wanted
	Frags     []uint16 // list of fragment indicies wanted

	// not marshaled
	SourceMAC net.HardwareAddr
}

func (*WantPacket) MarshalBinary

func (p *WantPacket) MarshalBinary() ([]byte, error)

func (*WantPacket) Source

func (p *WantPacket) Source() net.HardwareAddr

func (*WantPacket) UnmarshalBinary

func (p *WantPacket) UnmarshalBinary(data []byte) error

Directories

Path Synopsis
cmd
internal
lru
mlq

Jump to

Keyboard shortcuts

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