- Fix GetPrefixDistribution to count unique prefixes using COUNT(DISTINCT prefix) instead of COUNT(*) - Add /prefixlength/<length> route showing random sample of 500 prefixes - Make prefix counts on status page clickable links to prefix length pages - Add GetRandomPrefixesByLength database method - Create prefix_length.html template with sortable table - Show prefix age and origin AS with descriptions
65 lines
1.8 KiB
Go
65 lines
1.8 KiB
Go
package database
|
|
|
|
import (
|
|
"time"
|
|
)
|
|
|
|
// Stats contains database statistics
|
|
type Stats struct {
|
|
ASNs int
|
|
Prefixes int
|
|
IPv4Prefixes int
|
|
IPv6Prefixes int
|
|
Peerings int
|
|
Peers int
|
|
FileSizeBytes int64
|
|
LiveRoutes int
|
|
IPv4PrefixDistribution []PrefixDistribution
|
|
IPv6PrefixDistribution []PrefixDistribution
|
|
}
|
|
|
|
// Store defines the interface for database operations
|
|
type Store interface {
|
|
// ASN operations
|
|
GetOrCreateASN(number int, timestamp time.Time) (*ASN, error)
|
|
GetOrCreateASNBatch(asns map[int]time.Time) error
|
|
|
|
// Prefix operations
|
|
GetOrCreatePrefix(prefix string, timestamp time.Time) (*Prefix, error)
|
|
|
|
// Announcement operations
|
|
RecordAnnouncement(announcement *Announcement) error
|
|
|
|
// Peering operations
|
|
RecordPeering(asA, asB int, timestamp time.Time) error
|
|
|
|
// Statistics
|
|
GetStats() (Stats, error)
|
|
|
|
// Peer operations
|
|
UpdatePeer(peerIP string, peerASN int, messageType string, timestamp time.Time) error
|
|
UpdatePeerBatch(peers map[string]PeerUpdate) error
|
|
|
|
// Live route operations
|
|
UpsertLiveRoute(route *LiveRoute) error
|
|
UpsertLiveRouteBatch(routes []*LiveRoute) error
|
|
DeleteLiveRoute(prefix string, originASN int, peerIP string) error
|
|
DeleteLiveRouteBatch(deletions []LiveRouteDeletion) error
|
|
GetPrefixDistribution() (ipv4 []PrefixDistribution, ipv6 []PrefixDistribution, err error)
|
|
GetLiveRouteCounts() (ipv4Count, ipv6Count int, err error)
|
|
|
|
// IP lookup operations
|
|
GetASInfoForIP(ip string) (*ASInfo, error)
|
|
|
|
// AS and prefix detail operations
|
|
GetASDetails(asn int) (*ASN, []LiveRoute, error)
|
|
GetPrefixDetails(prefix string) ([]LiveRoute, error)
|
|
GetRandomPrefixesByLength(maskLength, ipVersion, limit int) ([]LiveRoute, error)
|
|
|
|
// Lifecycle
|
|
Close() error
|
|
}
|
|
|
|
// Ensure Database implements Store
|
|
var _ Store = (*Database)(nil)
|