Documentation ¶
Index ¶
- Constants
- Variables
- func AlwaysPrintf(format string, a ...interface{})
- func Caller(upStack int) string
- func DirExists(name string) bool
- func FileExists(name string) bool
- func FileLine(depth int) string
- func FileSize(name string) (int64, error)
- func GenAddress() string
- func GetAvailPort() int
- func GetExternalIP() string
- func GetExternalIPAsInt() int
- func HostKeyVerifies(knownKeysPath string, connState *tls.ConnectionState, remoteAddr string) (good, bad []string, wasNew bool, err0 error)
- func IsLocalhost(ipStr string) (isLocal bool, hostOnlyNoPort string)
- func IsRoutableIPv4(ip string) bool
- func IsWritable(path string) bool
- func LoadClientTLSConfig(embedded bool, sslCA, sslCert, sslCertKey string) (*tls.Config, error)
- func LoadClientTLSConfigFilesystem(sslCA, sslCert, sslCertKey string) (*tls.Config, error)
- func LoadServerTLSConfig(embedded bool, sslCA, sslClientCA, sslCert, sslCertKey string) (*tls.Config, error)
- func LoadServerTLSConfigFilesystem(sslCA, sslClientCA, sslCert, sslCertKey string) (*tls.Config, error)
- func LocalAddrMatching(addr string) (local string, err error)
- func P(format string, a ...interface{})
- func PB(w io.Writer, format string, a ...interface{})
- func PP(format string, a ...interface{})
- func PPP(format string, a ...interface{})
- func Printf(format string, a ...interface{}) (n int, err error)
- func QPrintf(format string, a ...interface{}) (n int, err error)
- func SelfyNewKey(createKeyPairNamed, odir string) error
- func StripNanomsgAddressPrefix(nanomsgAddr string) (suffix string, err error)
- func TSPrintf(format string, a ...interface{})
- func VPrintf(format string, a ...interface{}) (n int, err error)
- func VV(format string, a ...interface{})
- func WaitUntilCanConnect(addr string)
- func WrapWithBrackets(local string) string
- type CallbackFunc
- type Client
- func (c *Client) Close() error
- func (c *Client) Err() error
- func (c *Client) GetOneRead(seqno uint64, ch chan *Message)
- func (c *Client) GetReadIncomingCh() (ch chan *Message)
- func (c *Client) GetReads(ch chan *Message)
- func (c *Client) LocalAddr() string
- func (c *Client) OneWaySend(msg *Message, doneCh <-chan struct{}) (err error)
- func (c *Client) RunClientMain(serverAddr string, tcp_only bool, certPath string)
- func (c *Client) RunClientTCP(serverAddr string)
- func (c *Client) RunQUIC(localHostPort, quicServerAddr string, tlsConfig *tls.Config)
- func (c *Client) RunReadLoop(conn net.Conn)
- func (c *Client) RunSendLoop(conn net.Conn)
- func (c *Client) SendAndGetReply(req *Message, doneCh <-chan struct{}) (reply *Message, err error)
- func (c *Client) SendAndGetReplyWithTimeout(timeout time.Duration, req *Message) (reply *Message, err error)
- func (c *Client) SetLocalAddr(local string)
- func (c *Client) UngetReads(ch chan *Message)
- type Config
- type Known
- type KnownKey
- type MID
- func (mid *MID) AsGreenpack(scratch []byte) (o []byte, err error)
- func (m *MID) Bytes() []byte
- func (m *MID) Compact() string
- func (z *MID) DecodeMsg(dc *msgp.Reader) (err error)
- func (z *MID) EncodeMsg(en *msgp.Writer) (err error)
- func (a *MID) Equal(b *MID) bool
- func (m *MID) JSON() []byte
- func (z *MID) MarshalMsg(b []byte) (o []byte, err error)
- func (z *MID) Msgsize() (s int)
- func (m *MID) OpaqueURLFriendly() string
- func (m *MID) Pretty() string
- func (m *MID) String() string
- func (z *MID) UnmarshalMsg(bts []byte) (o []byte, err error)
- func (z *MID) UnmarshalMsgWithCfg(bts []byte, cfg *msgp.RuntimeConfig) (o []byte, err error)
- type Message
- func (m *Message) AsGreenpack(scratch []byte) (o []byte, err error)
- func (z *Message) DecodeMsg(dc *msgp.Reader) (err error)
- func (z *Message) EncodeMsg(en *msgp.Writer) (err error)
- func (z *Message) MarshalMsg(b []byte) (o []byte, err error)
- func (z *Message) Msgsize() (s int)
- func (msg *Message) String() string
- func (z *Message) UnmarshalMsg(bts []byte) (o []byte, err error)
- func (z *Message) UnmarshalMsgWithCfg(bts []byte, cfg *msgp.RuntimeConfig) (o []byte, err error)
- type NetConnWrapper
- type QUIC_RWPair
- type RWPair
- type Server
- func (s *Server) Close() error
- func (s *Server) NewQUIC_RWPair(stream quic.Stream, conn quic.Connection) *QUIC_RWPair
- func (s *Server) NewRWPair(conn net.Conn) *RWPair
- func (s *Server) RegisterFunc(callme CallbackFunc)
- func (s *Server) RunQUICServer(quicServerAddr string, tlsConfig *tls.Config, boundCh chan net.Addr)
- func (s *Server) RunServerMain(serverAddress string, tcp_only bool, certPath string, boundCh chan net.Addr)
- func (s *Server) RunTCP(serverAddress string, boundCh chan net.Addr)
- func (s *Server) SendMessage(callID, subject, destAddr string, by []byte, seqno uint64) error
- func (s *Server) Start() (serverAddr net.Addr, err error)
- type SharedTransport
Constants ¶
const RFC3339MsecTz0 = "2006-01-02T15:04:05.000Z07:00"
const RFC3339NanoNumericTZ0pad = "2006-01-02T15:04:05.000000000-07:00"
const VersionByteBase59Checked byte = 255
we always use 255, which is -1 in 8-bit 2's compliment.
Variables ¶
var Chicago *time.Location
var ErrDone = fmt.Errorf("done channel closed")
var ErrNetConnectionNotFound = fmt.Errorf("error: net.Conn not found")
var ErrNotFound = fmt.Errorf("known_tls_hosts file not found")
var ErrPubKeyMismath = fmt.Errorf("remote host pubkey does not match that on file!")
var ErrPubKeyUnknown = fmt.Errorf("remote host pubkey is not on file, and TOFU is off!")
var ErrShutdown = fmt.Errorf("shutting down")
var ForceQuiet = false
useful during git bisect
var Frankfurt *time.Location
var GTZ *time.Location
var London *time.Location
var MyPid = os.Getpid()
var NYC *time.Location
var OurStdout io.Writer = os.Stdout
so we can multi write easily, use our own printf
var ShowPid bool
var UtcTz *time.Location
var Verbose bool = false
for tons of debug output
var VerboseVerbose bool = false
Functions ¶
func AlwaysPrintf ¶
func AlwaysPrintf(format string, a ...interface{})
func FileExists ¶
func GenAddress ¶
func GenAddress() string
GenAddress generates a local address by calling GetAvailPort() and GetExternalIP(), then prefixing them with 'tcp://'.
func GetAvailPort ¶
func GetAvailPort() int
GetAvailPort asks the OS for an unused port. There's a race here, where the port could be grabbed by someone else before the caller gets to Listen on it, but in practice such races are rare. Uses net.Listen("tcp", ":0") to determine a free port, then releases it back to the OS with Listener.Close().
func GetExternalIP ¶
func GetExternalIP() string
GetExternalIP tries to determine the external IP address used on this host.
func GetExternalIPAsInt ¶
func GetExternalIPAsInt() int
GetExternalIPAsInt calls GetExternalIP() and then converts the resulting IPv4 string into an integer.
func HostKeyVerifies ¶
func HostKeyVerifies( knownKeysPath string, connState *tls.ConnectionState, remoteAddr string) (good, bad []string, wasNew bool, err0 error)
server will want stripPort true since client's port will change all the time. tofu true means we add any unknown cert to our knownKeysPath. We don't really care what the IP or hostname is, as long as we recognized a certified public key (in one of the identities), we accept. The IP or port could change, we don't care.
NB only ed25519 keys are permitted, any others will result in an immediate error and no further keys will be evaluated.
func IsLocalhost ¶ added in v1.0.12
func IsRoutableIPv4 ¶
IsRoutableIPv4 returns true if the string in ip represents an IPv4 address that is not private. See http://en.wikipedia.org/wiki/Private_network#Private_IPv4_address_spaces for the numeric ranges that are private. 127.0.0.1, 192.168.0.1, and 172.16.0.1 are examples of non-routables IP addresses.
func IsWritable ¶
IsWritable returns true if the file does not exist. Otherwise it checks the write bits. If any write bits (owner, group, others) are set, then we return true. Otherwise false.
func LoadClientTLSConfig ¶
LoadClientTLSConfig creates a client TLSConfig by loading the CA and client certs. The following paths must be passed: - sslCA: path to the CA certificate - sslCert: path to the client certificate - sslCertKey: path to the client key If the path is prefixed with "embedded=", load the embedded certs.
embedded true means load from the static embedded files, created at compile time. If embedded is false, then we read from the filesystem.
func LoadServerTLSConfig ¶
func LoadServerTLSConfig(embedded bool, sslCA, sslClientCA, sslCert, sslCertKey string) (*tls.Config, error)
LoadServerTLSConfig creates a server TLSConfig by loading the CA and server certs. The following paths must be passed:
- sslCA: path to the CA certificate
- sslClientCA: path to the CA certificate to verify client certificates, can be the same as sslCA
- sslCert: path to the server certificate
- sslCertKey: path to the server key
embedded true means load from the static embedded files, created at compile time. If embedded is false, then we read from the filesystem.
func LocalAddrMatching ¶ added in v1.0.7
LocalAddrMatching finds a matching interface IP to a server destination address
addr should b "host:port" of server, we'll find the local IP to use.
func PPP ¶
func PPP(format string, a ...interface{})
without the file/line, otherwise the same as PP
func Printf ¶
Printf formats according to a format specifier and writes to standard output. It returns the number of bytes written and any write error encountered.
func SelfyNewKey ¶ added in v1.0.3
odir/my-keep-private-dir and odir/certs will be created.
func StripNanomsgAddressPrefix ¶
StripNanomsgAddressPrefix removes the 'tcp://' prefix from nanomsgAddr.
func WaitUntilCanConnect ¶
func WaitUntilCanConnect(addr string)
func WrapWithBrackets ¶ added in v1.0.7
if it needs [] ipv6 brackets, add them
Types ¶
type CallbackFunc ¶
CallbackFunc is the user's own function that they register with the server for remote procedure calls.
The user's CallbackFunc may not want to return anything. In that case they should return nil. It will then be a 'one-way' function, and no reply will be returned over the network.
If the user's CallbackFunc wants to reply, they should modify the inputMsg.JobSerz bytes and then return the modified inputMsg as the outputMsg. This can be as simple as setting inputMsg.JobSerz = nil, or encoding a reponse into JobSerz, or encoding an error into JobSerz.
At the moment Message.Err is only for local system errors and is not sent on the wire. Hence it is not available to to communicate user job errors.
The system will overwrite the outputMsg.MID field while sending the reply, so the user should not bother changing it.
type Client ¶
type Client struct { Conn uConnLR // Conn net.Conn // the default. QuicConn quic.Connection // if connecting suceeds, a nil will be sent; else the error. Connected chan error // contains filtered or unexported fields }
Clients write requests, and maybe wait for responses.
func (*Client) GetOneRead ¶
auto unregister after a single send on ch.
func (*Client) GetReadIncomingCh ¶
func (*Client) OneWaySend ¶
doneCh is optional, can be nil.
func (*Client) RunClientMain ¶
eg. serverAddr = "localhost:8443" serverAddr = "192.168.254.151:8443"
func (*Client) RunClientTCP ¶
func (*Client) RunReadLoop ¶
func (*Client) RunSendLoop ¶
func (*Client) SendAndGetReply ¶
doneCh is optional; can be nil.
func (*Client) SendAndGetReplyWithTimeout ¶
func (*Client) SetLocalAddr ¶ added in v1.0.17
func (*Client) UngetReads ¶
un-register to get any received messages on ch.
type Config ¶
type Config struct { // ServerAddr host:port that the rpc25519.Server should bind to. ServerAddr string // optional. Can be used to force client to use a specific host:port; // say for port sharing with a server. ClientHostPort string // Who the client should contact ClientDialToHostPort string // TCP false means TLS-1.3 secured. true here means do TCP only. TCPonly_no_TLS bool // UseQUIC cannot be true if TCPonly_no_TLS is true. UseQUIC bool // path to certs/ like certificate // directory on the live filesystem. If left // empty then the embedded certs/ from build-time, those // copied from the on-disk certs/ directory and baked // into the executable as a virtual file system with // the go:embed directive are used. CertPath string // SkipVerifyKeys true allows any incoming // key to be signed by // any CA; it does not have to be ours. Obviously // this discards almost all access control; it // should rarely be used unless communication // with the any random agent/hacker/public person // is desired. SkipVerifyKeys bool ClientKeyPairName string // default "client" means use certs/client.crt and certs/client.key ServerKeyPairName string // default "node" means use certs/node.crt and certs/node.key // These are timeouts for connection and transport tuning. // The defaults of 0 mean wait forever. ConnectTimeout time.Duration ReadTimeout time.Duration WriteTimeout time.Duration LocalAddress string // contains filtered or unexported fields }
Config says who to contact (for a client), or where to listen (for a server); and sets how strong a security posture we adopt.
Copying a Config is fine, but it should be a simple shallow copy to preserve the shared *SharedTransport struct.
This shared pointer is the basis of port (and file handle) reuse where a single process can maintain a server and multiple clients in a "star" pattern. This only works with QUIC of course, and is one of the main reasons to use QUIC. The shared pointer is reference counted and the underlying net.UDPConn is only closed when the last instance in use is Close()-ed.
type Known ¶
type KnownKey ¶
type KnownKey struct { Addr string // 192.168.254.151:8443 KeyType string // ed25519 PubKey string // 9aTjVYv1K7vj3WYX3EktjaGPycNwym5Rn5Vo1WuxLdF7bxpMDV6 Emails string Line int }
KnownKey saved to a file results in lines like 127.0.0.1 pubkey@edwardsRPC-ed25519-b58c-9ZrrEXxvoqmj9UkgiPjHNZP41N9wuLyQTEUCg5S7VjPuJbXXL8a:froggy@example.com
func (*KnownKey) IdentityString ¶
e.g. "pubkey@edwardsRPC-ed25519-b58c-9ZrrEXxvoqmj9UkgiPjHNZP41N9wuLyQTEUCg5S7VjPuJbXXL8a:froggy@example.com"
type MID ¶
type MID struct { Created string `zid:"0"` From string `zid:"1"` To string `zid:"2"` Subject string `zid:"3"` IsRPC bool `zid:"4"` IsLeg2 bool `zid:"5"` Serial int64 `zid:"6"` CallID string `zid:"7"` // able to match call and response on this alone. PID int64 `zid:"8"` Seqno uint64 `zid:"9"` }
The Multiverse Identitifer: for when there are multiple universes and so a UUID just won't do.
func MIDFromBytes ¶
func MIDFromGreenpack ¶
workspace can be nil or reused to avoid allocation.
func (*MID) AsGreenpack ¶
the scrach workspace can be nil or reused to avoid allocation.
func (*MID) DecodeMsg ¶
DecodeMsg implements msgp.Decodable We treat empty fields as if we read a Nil from the wire.
func (*MID) MarshalMsg ¶
MarshalMsg implements msgp.Marshaler
func (*MID) Msgsize ¶
Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message
func (*MID) OpaqueURLFriendly ¶
func (*MID) UnmarshalMsg ¶
UnmarshalMsg implements msgp.Unmarshaler
func (*MID) UnmarshalMsgWithCfg ¶
type Message ¶
type Message struct { Nc net.Conn `msg:"-"` Seqno uint64 `zid:"0"` Subject string `zid:"1"` MID MID `zid:"2"` JobSerz []byte `zid:"3"` JobErrs string `zid:"4"` // Err is not serialized on the wire by the server, // so communicates only local information. Callback // functions should convey errors in-band within // JobSerz. Err error `msg:"-"` DoneCh chan *Message `msg:"-"` }
Message basic substrate.
func MessageFromGreenpack ¶ added in v1.0.28
func NewMessage ¶
func NewMessage() *Message
func NewMessageFromBytes ¶
func (*Message) AsGreenpack ¶ added in v1.0.29
the scrach workspace can be nil or reused to avoid allocation.
func (*Message) DecodeMsg ¶ added in v1.0.26
DecodeMsg implements msgp.Decodable We treat empty fields as if we read a Nil from the wire.
func (*Message) MarshalMsg ¶ added in v1.0.26
MarshalMsg implements msgp.Marshaler
func (*Message) Msgsize ¶ added in v1.0.26
Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message
func (*Message) UnmarshalMsg ¶ added in v1.0.26
UnmarshalMsg implements msgp.Unmarshaler
func (*Message) UnmarshalMsgWithCfg ¶ added in v1.0.26
type NetConnWrapper ¶ added in v1.0.5
type NetConnWrapper struct { quic.Stream quic.Connection }
type QUIC_RWPair ¶ added in v1.0.5
type QUIC_RWPair struct { RWPair Stream quic.Stream }
type RWPair ¶
type RWPair struct { // our parent Server Server *Server Conn net.Conn SendCh chan *Message // contains filtered or unexported fields }
keep the pair of goroutines running the read loop and the write loop for a given connection together so we can figure out who to SendCh to and how to halt each other.
type Server ¶
type Server struct { // remote when server gets a new client, // So test 004 can avoid a race/panic. RemoteConnectedCh chan string // contains filtered or unexported fields }
Servers read and respond to requests. Server.Register() says which CallbackFunc to call. Only one call back func is supported at the moment.
func NewServer ¶
NewServer will keep its own copy of config. If config is nil, the server will make its own upon Start().
func (*Server) NewQUIC_RWPair ¶ added in v1.0.5
func (s *Server) NewQUIC_RWPair(stream quic.Stream, conn quic.Connection) *QUIC_RWPair
func (*Server) RegisterFunc ¶
func (s *Server) RegisterFunc(callme CallbackFunc)
func (*Server) RunQUICServer ¶ added in v1.0.5
func (*Server) RunServerMain ¶
func (s *Server) RunServerMain(serverAddress string, tcp_only bool, certPath string, boundCh chan net.Addr)
boundCh should be buffered, at least 1, if it is not nil. If not nil, we will send the bound net.Addr back on it after we have started listening.
func (*Server) SendMessage ¶
type SharedTransport ¶ added in v1.0.14
type SharedTransport struct {
// contains filtered or unexported fields
}