- Add prepared statements to all batch operations for better performance - Fix database lock contention by properly batching operations - Update SQLite settings for extreme performance (8GB cache, sync OFF) - Add proper error handling for statement closing - Update tests to properly track batch operations
95 lines
2.7 KiB
Go
95 lines
2.7 KiB
Go
package database
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
// ASN represents an Autonomous System Number
|
|
type ASN struct {
|
|
ID uuid.UUID `json:"id"`
|
|
Number int `json:"number"`
|
|
Handle string `json:"handle"`
|
|
Description string `json:"description"`
|
|
FirstSeen time.Time `json:"first_seen"`
|
|
LastSeen time.Time `json:"last_seen"`
|
|
}
|
|
|
|
// Prefix represents an IP prefix (CIDR block)
|
|
type Prefix struct {
|
|
ID uuid.UUID `json:"id"`
|
|
Prefix string `json:"prefix"`
|
|
IPVersion int `json:"ip_version"` // 4 or 6
|
|
FirstSeen time.Time `json:"first_seen"`
|
|
LastSeen time.Time `json:"last_seen"`
|
|
}
|
|
|
|
// Announcement represents a BGP announcement
|
|
type Announcement struct {
|
|
ID uuid.UUID `json:"id"`
|
|
PrefixID uuid.UUID `json:"prefix_id"`
|
|
ASNID uuid.UUID `json:"asn_id"`
|
|
OriginASNID uuid.UUID `json:"origin_asn_id"`
|
|
Path string `json:"path"` // JSON-encoded AS path
|
|
NextHop string `json:"next_hop"`
|
|
Timestamp time.Time `json:"timestamp"`
|
|
IsWithdrawal bool `json:"is_withdrawal"`
|
|
}
|
|
|
|
// ASNPeering represents a peering relationship between two ASNs
|
|
type ASNPeering struct {
|
|
ID uuid.UUID `json:"id"`
|
|
FromASNID uuid.UUID `json:"from_asn_id"`
|
|
ToASNID uuid.UUID `json:"to_asn_id"`
|
|
FirstSeen time.Time `json:"first_seen"`
|
|
LastSeen time.Time `json:"last_seen"`
|
|
}
|
|
|
|
// LiveRoute represents a route in the live routing table
|
|
type LiveRoute struct {
|
|
ID uuid.UUID `json:"id"`
|
|
Prefix string `json:"prefix"`
|
|
MaskLength int `json:"mask_length"`
|
|
IPVersion int `json:"ip_version"`
|
|
OriginASN int `json:"origin_asn"`
|
|
PeerIP string `json:"peer_ip"`
|
|
ASPath []int `json:"as_path"`
|
|
NextHop string `json:"next_hop"`
|
|
LastUpdated time.Time `json:"last_updated"`
|
|
// IPv4 range fields for fast lookups (nil for IPv6)
|
|
V4IPStart *uint32 `json:"v4_ip_start,omitempty"`
|
|
V4IPEnd *uint32 `json:"v4_ip_end,omitempty"`
|
|
}
|
|
|
|
// PrefixDistribution represents the distribution of prefixes by mask length
|
|
type PrefixDistribution struct {
|
|
MaskLength int `json:"mask_length"`
|
|
Count int `json:"count"`
|
|
}
|
|
|
|
// ASInfo represents AS information for an IP lookup
|
|
type ASInfo struct {
|
|
ASN int `json:"asn"`
|
|
Handle string `json:"handle"`
|
|
Description string `json:"description"`
|
|
Prefix string `json:"prefix"`
|
|
LastUpdated time.Time `json:"last_updated"`
|
|
Age string `json:"age"`
|
|
}
|
|
|
|
// LiveRouteDeletion represents parameters for deleting a live route
|
|
type LiveRouteDeletion struct {
|
|
Prefix string
|
|
OriginASN int
|
|
PeerIP string
|
|
}
|
|
|
|
// PeerUpdate represents parameters for updating a peer
|
|
type PeerUpdate struct {
|
|
PeerIP string
|
|
PeerASN int
|
|
MessageType string
|
|
Timestamp time.Time
|
|
}
|