package cachedb import ( `net` `time` `github.com/jmoiron/sqlx` `r00t2.io/gobroke/tunnelbroker` ) /* Cache is used to access a database holding historical tunnel configuration and update information. This is primarily used to keep request load low and update load even lower to tunnelbroker.net servers. */ type Cache struct { db *sqlx.DB } /* DbTunnel is a cached tunnelbroker.Tunnel paired with a conf.Tunnel checksum. It is used to compare defined tunnels on restart, and can be used to fetch last-known usptream configuration. If the CRC32 mismatches, an update will be forced. Otherwise it is subject to normal frequency rates for checking. */ type DbTunnel struct { *tunnelbroker.Tunnel // CRC32 is a checksum of *the associated conf.Tunnel*, NOT the upstream tunnel configuration. CRC32 uint32 `db:"cksum_crc32"` // Created is when this *row* is created. Created time.Time `db:"created"` // Checked is when the client IP was last checked against the live configuration at tunnelbroker.net. Checked time.Time `db:"checked"` // Updated is when the client IP was last updated at tunnelbroker.net (by GoBroke), *or* the Tunnel changed. Updated time.Time `db:"updated"` } /* DbClientIP contains a row describing a result of a client IP fetch from a dynamic service (e.g. https://c4.r00t2.io/). If an explicit address is provided for a conf.Tunnel, there will not be a corresponding row for it. This is only a history of publicly fetched IPs. */ type DbClientIP struct { // ID is a row identifier serving as primary key; it doesn't have any particular significance beyond that. ID uint `db:"id"` // TunID corresponds to a DbTunnel.Tunnel.ID. It is foreign keyed against it. TunID uint `db:"tun_id"` // ClientIPv4 is the client-end registered for tunnel TunID. ClientIPv4 net.IP `db:"client_ip"` // Set specifies when the IP was last set at tunnelbroker.net. Set time.Time `db:"when_set"` // Fetched specifies when the client IP was last *fetched* from a remote service. Fetched time.Time `db:"when_fetched"` }