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 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 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 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)
- 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) 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) 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
- type RWPair
- type Server
- func (s *Server) Close() error
- func (s *Server) NewRWPair(conn net.Conn) *RWPair
- func (s *Server) RegisterFunc(callme CallbackFunc)
- 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)
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 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 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 StripNanomsgAddressPrefix ¶
StripNanomsgAddressPrefix removes the 'tcp://' prefix from nanomsgAddr.
func WaitUntilCanConnect ¶
func WaitUntilCanConnect(addr string)
Types ¶
type CallbackFunc ¶
CallbackFunc is the user's own function that they register with the server for remote procedure calls.
The users's func may not want to return anything: be a one-way. In that case they should return nil in out.
If they want to return anything, even an error, they must allocate with rpc25519.NewMessage() and return that (in out). The out.Err field can be assigned for an error to be returned. The JobSerz []byte are the main place to return structured information, but it can be nil if there is only an error. It is fine to set neither and still allocate out. The caller will get a response that no error was encountered.
A one-way function is equivalent to returning nil. No reply will be sent to the caller, and so they hopefully sent using SendOneWay(). This may be desired though: a later asynchronous server push will unblock them.
type Client ¶
type Client struct { Conn net.Conn // the default. // 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) UngetReads ¶
un-register to get any received messages on ch.
type Config ¶
type Config struct { // ServerAddr host:port of the rpc25519.Server to contact. ServerAddr string // TCP false means TLS-1.3 secured. true here means do TCP only. TCPonly_no_TLS 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 KeyPairName string // default "client" means use certs/client.crt and certs/client.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 }
Config says who to contact (for a client), or where to listen (for a server); and sets how strong a security posture we adopt.
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"` }
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 Seqno uint64 Subject string // intent. example: "rpc call to ThisFunc()" MID MID JobSerz []byte // 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 DoneCh chan *Message }
func NewMessage ¶
func NewMessage() *Message
func NewMessageFromBytes ¶
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 (*Server) RegisterFunc ¶
func (s *Server) RegisterFunc(callme CallbackFunc)
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.