Skip to main content

magpipe 0.3.5 copy "magpipe: ^0.3.5" to clipboard
magpipe: ^0.3.5 copied to clipboard

Magpie Bridge pipe transport: shared-socket UDP connections (hub), packet framing for bridge/direct links, and the enigma secret box (HKDF-SHA256 + AES-256-GCM).

magpipe #

License PRs Welcome Platform Issues Repo Size Tags Version

Watchers Forks Stars Followers

Magpie Bridge pipe transport for Dart: one shared UDP socket, many connections.

  • MagHub: binds the shared socket once and multiplexes every connection registered on it (inbound datagrams are routed by remote endpoint). The hub runs no timers: call hub.keepAlive(now) periodically (e.g. once a second on your own timer) to heartbeat idle links and re-connect dead ones (docs/client.md §6, §8). hub.close() disconnects everything and closes the shared socket.
  • BridgeLink / DirectLink: connection to the relay server (B=1, with the SYN?/SYN!/ACK! handshake, heartbeat and enigma) or directly to a peer (B=0, stateless).
  • Packet framing: bridge/direct packet classes and factories (SYN?/SYN!/ACK!, FAIL/DONE, ACPT/DENY, PING/PONG, FIN?/FIN!, NOOP, DATA/COPY), including signed ReliablePacket (HMAC-SHA256).
  • Enigma: decrypts the handshake secret with HKDF-SHA256 + AES-256-GCM (HkdfEnc / HkdfSha256).
  • Receiving: the default processPacket answers "COPY" to data packets and "PONG" to heartbeats; override it on your pipe subclass to plug in your own dedup, fragment reassembly and delivery.
  • Observing: a MagpieDelegate receives every packet received through the link - handshake waves included; set it on the shared MagpieExtensions (delegate) without subclassing anything.

See docs/protocol.md in the Magpie Bridge repository for the wire format and docs/client.md for the client behaviour.

Usage #

var enigma = Enigma();  // feeds the encrypted handshake
var config = Config();  // timing knobs (heartbeat/handshake intervals, ...)

var hub = await MagHub.create(enigma: enigma, config: config);

// pipes are built by the registered factory (required); the delegate
// observes every packet received through the links (optional):
sharedMagpieExtensions.pipeFactory = PipeFactory();
sharedMagpieExtensions.delegate = MyDelegate();

// bridge connection to the relay server (B=1):
var bridge = hub.connectBridge(server);
// the handshake runs in the background: getBridgePipe returns null
// until it completes (bridge.ready)
var bridgePipe = hub.getBridgePipe(server, targetBid);

// direct connection to a peer (B=0):
var direct = hub.connect(peer);
var directPipe = hub.getDirectPipe(peer);

// send data through a pipe (sn/index/count for the reliability layer):
directPipe.sendData(payload, sn: 1);

// or send a pre-built packet (routed by its B flag):
hub.sendPacket(packet, remote: server);

// keep-alive pass: call periodically, e.g. once a second
hub.keepAlive(DateTime.now());

...
hub.disconnect(server);

// done: disconnects every link and closes the shared socket
hub.close();

License #

MIT — see LICENSE.

0
likes
0
points
773
downloads

Publisher

unverified uploader

Weekly Downloads

Magpie Bridge pipe transport: shared-socket UDP connections (hub), packet framing for bridge/direct links, and the enigma secret box (HKDF-SHA256 + AES-256-GCM).

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

magpie_bridge, pointycastle

More

Packages that depend on magpipe