Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup server code a bit #111

Merged
merged 6 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion cmd/stayrtr/stayrtr.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ var (
RefreshRTR = flag.Int("rtr.refresh", 3600, "Refresh interval")
RetryRTR = flag.Int("rtr.retry", 600, "Retry interval")
ExpireRTR = flag.Int("rtr.expire", 7200, "Expire interval")
SendNotifs = flag.Bool("notifications", true, "Send notifications to clients (disable with -notifications=false)")
EnforceVersion = flag.Bool("enforce.version", false, "Disable version negotiation")
DisableBGPSec = flag.Bool("disable.bgpsec", false, "Disable sending out BGPSEC Router Keys")
DisableASPA = flag.Bool("disable.aspa", false, "Disable sending out ASPA objects")
EnableNODELAY = flag.Bool("enable.nodelay", false, "Force enable TCP NODELAY (Likely increases CPU)")


Bind = flag.String("bind", ":8282", "Bind address")

Expand Down Expand Up @@ -83,7 +89,6 @@ var (
Mime = flag.String("mime", "application/json", "Accept setting format (some servers may prefer text/json)")
RefreshInterval = flag.Int("refresh", 600, "Refresh interval in seconds")
MaxConn = flag.Int("maxconn", 0, "Max simultaneous connections (0 to disable limit)")
SendNotifs = flag.Bool("notifications", true, "Send notifications to clients (disable with -notifications=false)")

Slurm = flag.String("slurm", "", "Slurm configuration file (filters and assertions)")
SlurmRefresh = flag.Bool("slurm.refresh", true, "Refresh along the cache (disable with -slurm.refresh=false)")
Expand Down Expand Up @@ -755,6 +760,11 @@ func run() error {
RefreshInterval: uint32(*RefreshRTR),
RetryInterval: uint32(*RetryRTR),
ExpireInterval: uint32(*ExpireRTR),

EnforceVersion: *EnforceVersion,
DisableBGPSec: *DisableBGPSec,
DisableASPA: *DisableASPA,
EnableNODELAY: *EnableNODELAY,
}

var me *metricsEvent
Expand Down
33 changes: 16 additions & 17 deletions lib/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package rtrlib
import (
"bytes"
"crypto/tls"
"flag"
"fmt"
"io"
"math"
Expand Down Expand Up @@ -134,6 +133,9 @@ type Server struct {
handler RTRServerEventHandler
simpleHandler RTREventHandler
enforceVersion bool
disableBGPSec bool
disableASPA bool
enableNODELAY bool

sdlock *sync.RWMutex
sdListDiff [][]SendableData
Expand All @@ -157,6 +159,10 @@ type ServerConfiguration struct {

SessId int

DisableBGPSec bool
DisableASPA bool
EnableNODELAY bool

RefreshInterval uint32
RetryInterval uint32
ExpireInterval uint32
Expand Down Expand Up @@ -196,14 +202,18 @@ func NewServer(configuration ServerConfiguration, handler RTRServerEventHandler,
sessId: sessids,
maxconn: configuration.MaxConn,
baseVersion: configuration.ProtocolVersion,

enforceVersion: configuration.EnforceVersion,
handler: handler,
simpleHandler: simpleHandler,
disableBGPSec: configuration.DisableBGPSec,
disableASPA: configuration.DisableASPA,

pduRefreshInterval: refreshInterval,
pduRetryInterval: retryInterval,
pduExpireInterval: expireInterval,

handler: handler,
simpleHandler: simpleHandler,

log: configuration.Log,
logverbose: configuration.LogVerbose,
}
Expand Down Expand Up @@ -479,12 +489,8 @@ func (s *Server) Start(bind string) error {
return s.loopTCP(tcplist, "tcp", s.acceptClientTCP)
}

var DisableBGPSec = flag.Bool("disable.bgpsec", false, "Disable sending out BGPSEC Router Keys")
var DisableASPA = flag.Bool("disable.aspa", false, "Disable sending out ASPA objects")
var EnableNODELAY = flag.Bool("enable.nodelay", false, "Force enable TCP NODELAY (Likely increases CPU)")

func (s *Server) acceptClientTCP(tcpconn net.Conn) error {
if !*EnableNODELAY {
if !s.enableNODELAY {
tc, ok := tcpconn.(*net.TCPConn)
if ok {
tc.SetNoDelay(false)
Expand All @@ -497,10 +503,10 @@ func (s *Server) acceptClientTCP(tcpconn net.Conn) error {
client.SetVersion(s.baseVersion)
}
client.SetIntervals(s.pduRefreshInterval, s.pduRetryInterval, s.pduExpireInterval)
if *DisableBGPSec {
if s.disableBGPSec {
client.DisableBGPsec()
}
if *DisableASPA {
if s.disableASPA {
client.DisableASPA()
}
go client.Start()
Expand Down Expand Up @@ -630,19 +636,12 @@ func (s *Server) GetClientList() []*Client {

func (s *Server) NotifyClientsLatest() {
serial, _ := s.GetCurrentSerial()

clients := s.GetClientList()
for _, c := range clients {
c.Notify(s.GetSessionId(c.GetVersion()), serial)
}
}

func (s *Server) SendPDU(pdu PDU) {
for _, client := range s.clients {
client.SendPDU(pdu)
}
}

func ClientFromConn(tcpconn net.Conn, handler RTRServerEventHandler, simpleHandler RTREventHandler) *Client {
return &Client{
tcpconn: tcpconn,
Expand Down
2 changes: 1 addition & 1 deletion lib/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ func (pdu *PDUEndOfData) Write(wr io.Writer) {
if pdu.Version == PROTOCOL_VERSION_0 {
binary.Write(wr, binary.BigEndian, uint32(12))
binary.Write(wr, binary.BigEndian, pdu.SerialNumber)
} else if pdu.Version == PROTOCOL_VERSION_1 || pdu.Version == PROTOCOL_VERSION_2 {
} else {
binary.Write(wr, binary.BigEndian, uint32(24))
binary.Write(wr, binary.BigEndian, pdu.SerialNumber)
binary.Write(wr, binary.BigEndian, pdu.RefreshInterval)
Expand Down
Loading