Shared libraries for the IBP GeoDNS System v2, providing configuration management, data persistence, NATS messaging, health monitoring consensus, and geographic utilities.
IBP GeoDNS Libs is the foundational package that powers all IBP GeoDNS components with:
- Centralized configuration with hot-reload support
- MySQL persistence for events, usage, and metrics
- NATS-based distributed consensus protocol
- MaxMind GeoIP integration with auto-updates
- Matrix alerting for outage notifications
Unified configuration management for local and remote configs.
Features:
- Local JSON config loading
- Remote config fetching from GitHub with hot-reload
- Member override preservation during reloads
- Type-safe config structures
Key Functions:
Init(cfgFile string)- Initialize with local config pathGetConfig()- Thread-safe config retrievalGetMember(name)- Member lookup with override status
Two-tier data persistence layer for monitoring results and metrics.
data/ - Primary data layer:
- Official/local result storage with consensus updates
- Usage statistics with in-memory aggregation and incremental MySQL flushes
- Event recording for member outages
- 5-minute automatic flush to MySQL
data2/ - Collator-optimized layer:
- Per-node usage upserts (idempotent replacements, not increments)
- Network status tracking with vote data
- Proposal caching for consensus
- Matrix notification triggers
NATS messaging for distributed consensus and cluster coordination.
Consensus Protocol:
- Monitor proposes status change
- Other monitors vote based on local observations
- Majority consensus required (min 2 votes)
- Finalized results become official
Key Subjects:
consensus.propose- Status change proposalsconsensus.vote- Voting on proposalsconsensus.finalize- Consensus resultsdns.usage.*- Usage data collectionmonitor.stats.*- Downtime statistics
GeoIP database management with automatic updates.
Features:
- Auto-download of GeoLite2 databases (City, Country, ASN)
- HTTP Last-Modified tracking for updates
- Distance calculation using Haversine formula
- Country, ASN, and network lookups
Databases:
CityLite.mmdb- Lat/lon coordinatesCountryLite.mmdb- Country codesAsnLite.mmdb- Network information
Real-time alerting via Matrix protocol.
Features:
- Deduplicated OFFLINE alerts (one per outage)
- In-place edits for ONLINE recovery
- Member @mentions from config
- Automatic reconnection handling
Structured logging with configurable levels.
Levels: Debug, Info, Warn, Error, Fatal
go get github.com/ibp-network/ibp-geodns-libstype Config struct {
Local LocalConfig // Node-specific settings
StaticDNS []DNSRecord // Static DNS entries
Members map[string]Member // Infrastructure providers
Services map[string]Service // Service definitions
Pricing map[string]IaasPricing // Cost models
ServiceRequests ServiceRequests // Request statistics
Alerts AlertsConfig // Notification settings
}import cfg "github.com/ibp-network/ibp-geodns-libs/config"
cfg.Init("/path/to/config.json")
config := cfg.GetConfig()import dat "github.com/ibp-network/ibp-geodns-libs/data"
dat.Init(dat.InitOptions{
UseLocalOfficialCaches: false,
UseUsageStats: true,
})
dat.RecordDnsHit(false, "203.0.113.1", "rpc.example.com", "member1")import nats "github.com/ibp-network/ibp-geodns-libs/nats"
nats.ProposeCheckStatus(
"endpoint", // checkType
"wss", // checkName
"member1", // memberName
"rpc.example.com", // domainName
"wss://...", // endpoint
false, // status (offline)
"Connection timeout", // errorText
nil, // data
false, // isIPv6
)import max "github.com/ibp-network/ibp-geodns-libs/maxmind"
lat, lon := max.GetClientCoordinates("203.0.113.1")
country := max.GetCountryCode("203.0.113.1")
asn, network := max.GetAsnAndNetwork("203.0.113.1")
distance := max.Distance(lat1, lon1, lat2, lon2)CREATE TABLE member_events (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
member_name VARCHAR(255),
check_type VARCHAR(50),
check_name VARCHAR(100),
domain_name VARCHAR(255),
endpoint TEXT,
status BOOLEAN,
start_time TIMESTAMP,
end_time TIMESTAMP NULL,
error TEXT,
additional_data JSON,
is_ipv6 BOOLEAN,
KEY idx_member_status (member_name, status),
KEY idx_time (start_time, end_time)
);CREATE TABLE requests (
date DATE,
node_id VARCHAR(100),
domain_name VARCHAR(255),
member_name VARCHAR(255),
country_code CHAR(2),
network_asn VARCHAR(20),
network_name VARCHAR(255),
country_name VARCHAR(255),
is_ipv6 TINYINT(1),
hits INT,
PRIMARY KEY (date, node_id, domain_name, member_name,
network_asn, network_name, country_code,
country_name, is_ipv6)
);- Go 1.24.x or higher
- MySQL 5.7+ with UTC timezone
- NATS server cluster
- MaxMind account for GeoLite2
- Matrix homeserver (optional)
- Thread Safety: All shared state protected by mutexes
- Idempotency:
data2usage upserts replace per-node totals, whiledataflushes aggregated daily hits incrementally - Consensus: Minimum 2 votes + majority for status changes
- Hot Reload: Remote configs refresh without restart
- Deduplication: One alert per outage, edited on recovery
github.com/go-sql-driver/mysql- MySQL drivergithub.com/nats-io/nats.go- NATS messaginggithub.com/oschwald/maxminddb-golang- MaxMind readermaunium.net/go/mautrix- Matrix clientgithub.com/google/uuid- UUID generation
See LICENSE file in repository root.