mirror of
https://github.com/luxfi/zwing.git
synced 2026-09-24 00:24:38 +00:00
Composing PQ transport with ZAP RPC was already a 2-line pattern:
raw, _ := zwing.Dial(ctx, addr, cfg)
conn := zap.NewConn(raw, nil)
Two lines means two ways to mess it up (forget to wrap, leak the
raw conn). Add the canonical one-call wrappers so there is exactly
one way to do it:
conn, _ := zwing.DialZAP(ctx, addr, cfg)
ln, _ := zwing.ListenZAP(":9999", cfg)
srv := zap.NewServer(ln, handler)
Pairs with luxfi/api v1.0.10 zap.NewListener. No new wire format,
no new dep — these are sugar over the existing primitives.
44 lines
1.3 KiB
Go
44 lines
1.3 KiB
Go
// Copyright (C) 2020-2026, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package zwing
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/luxfi/api/zap"
|
|
)
|
|
|
|
// DialZAP opens a Z-Wing channel to addr and wraps it as a ZAP client
|
|
// connection. This is the canonical way to speak ZAP RPC over a PQ
|
|
// transport: one call, one composition, no chance of misuse.
|
|
//
|
|
// conn, err := zwing.DialZAP(ctx, "host:9999", &zwing.Config{
|
|
// LocalIdentity: myID,
|
|
// ExpectedRemote: pinnedServerPub, // optional
|
|
// })
|
|
// defer conn.Close()
|
|
// resp, payload, err := conn.Call(ctx, zap.MsgFoo, body)
|
|
func DialZAP(ctx context.Context, addr string, cfg *Config) (*zap.Conn, error) {
|
|
raw, err := Dial(ctx, addr, cfg)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return zap.NewConn(raw, nil), nil
|
|
}
|
|
|
|
// ListenZAP binds a Z-Wing listener at addr and returns a ZAP listener
|
|
// that accepts post-handshake encrypted ZAP connections. Pair with
|
|
// zap.NewServer to host an RPC service.
|
|
//
|
|
// ln, _ := zwing.ListenZAP(":9999", &zwing.Config{LocalIdentity: id})
|
|
// srv := zap.NewServer(ln, zap.HandlerFunc(handle))
|
|
// srv.Serve(ctx)
|
|
func ListenZAP(addr string, cfg *Config) (*zap.Listener, error) {
|
|
zln, err := Listen(addr, cfg)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return zap.NewListener(zln, nil), nil
|
|
}
|