repo
stringlengths
5
67
path
stringlengths
4
218
func_name
stringlengths
0
151
original_string
stringlengths
52
373k
language
stringclasses
6 values
code
stringlengths
52
373k
code_tokens
listlengths
10
512
docstring
stringlengths
3
47.2k
docstring_tokens
listlengths
3
234
sha
stringlengths
40
40
url
stringlengths
85
339
partition
stringclasses
3 values
google/seesaw
netlink/message.go
SendMessage
func SendMessage(command, family, flags int) error { return SendMessageCallback(command, family, flags, callbackDefault, nil) }
go
func SendMessage(command, family, flags int) error { return SendMessageCallback(command, family, flags, callbackDefault, nil) }
[ "func", "SendMessage", "(", "command", ",", "family", ",", "flags", "int", ")", "error", "{", "return", "SendMessageCallback", "(", "command", ",", "family", ",", "flags", ",", "callbackDefault", ",", "nil", ")", "\n", "}" ]
// SendMessage creates and sends a netlink message.
[ "SendMessage", "creates", "and", "sends", "a", "netlink", "message", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/netlink/message.go#L263-L265
train
google/seesaw
netlink/message.go
SendMessageCallback
func SendMessageCallback(command, family, flags int, cb CallbackFunc, arg interface{}) error { msg, err := NewMessage(command, family, flags) if err != nil { return err } defer msg.Free() return msg.SendCallback(cb, arg) }
go
func SendMessageCallback(command, family, flags int, cb CallbackFunc, arg interface{}) error { msg, err := NewMessage(command, family, flags) if err != nil { return err } defer msg.Free() return msg.SendCallback(cb, arg) }
[ "func", "SendMessageCallback", "(", "command", ",", "family", ",", "flags", "int", ",", "cb", "CallbackFunc", ",", "arg", "interface", "{", "}", ")", "error", "{", "msg", ",", "err", ":=", "NewMessage", "(", "command", ",", "family", ",", "flags", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "msg", ".", "Free", "(", ")", "\n", "return", "msg", ".", "SendCallback", "(", "cb", ",", "arg", ")", "\n", "}" ]
// SendMessageCallback creates and sends a netlink message. The specified // callback function will be called for each message that is received in // response.
[ "SendMessageCallback", "creates", "and", "sends", "a", "netlink", "message", ".", "The", "specified", "callback", "function", "will", "be", "called", "for", "each", "message", "that", "is", "received", "in", "response", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/netlink/message.go#L270-L278
train
google/seesaw
netlink/message.go
SendMessageMarshalled
func SendMessageMarshalled(command, family, flags int, v interface{}) error { msg, err := NewMessage(command, family, flags) if err != nil { return err } defer msg.Free() if err := msg.Marshal(v); err != nil { return err } return msg.Send() }
go
func SendMessageMarshalled(command, family, flags int, v interface{}) error { msg, err := NewMessage(command, family, flags) if err != nil { return err } defer msg.Free() if err := msg.Marshal(v); err != nil { return err } return msg.Send() }
[ "func", "SendMessageMarshalled", "(", "command", ",", "family", ",", "flags", "int", ",", "v", "interface", "{", "}", ")", "error", "{", "msg", ",", "err", ":=", "NewMessage", "(", "command", ",", "family", ",", "flags", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "msg", ".", "Free", "(", ")", "\n", "if", "err", ":=", "msg", ".", "Marshal", "(", "v", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "msg", ".", "Send", "(", ")", "\n", "}" ]
// SendMessageMarshalled creates a netlink message and marshals the given // struct into the message, before sending it.
[ "SendMessageMarshalled", "creates", "a", "netlink", "message", "and", "marshals", "the", "given", "struct", "into", "the", "message", "before", "sending", "it", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/netlink/message.go#L282-L293
train
google/seesaw
netlink/message.go
SendMessageUnmarshal
func SendMessageUnmarshal(command, family, flags int, v interface{}) error { return SendMessageCallback(command, family, flags, callbackUnmarshal, v) }
go
func SendMessageUnmarshal(command, family, flags int, v interface{}) error { return SendMessageCallback(command, family, flags, callbackUnmarshal, v) }
[ "func", "SendMessageUnmarshal", "(", "command", ",", "family", ",", "flags", "int", ",", "v", "interface", "{", "}", ")", "error", "{", "return", "SendMessageCallback", "(", "command", ",", "family", ",", "flags", ",", "callbackUnmarshal", ",", "v", ")", "\n", "}" ]
// SendMessageUnmarshal creates and sends a netlink message. All messages // received in response will be unmarshalled into the given struct.
[ "SendMessageUnmarshal", "creates", "and", "sends", "a", "netlink", "message", ".", "All", "messages", "received", "in", "response", "will", "be", "unmarshalled", "into", "the", "given", "struct", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/netlink/message.go#L297-L299
train
google/seesaw
binaries/seesaw_ha/main.go
config
func config(e ha.Engine) *seesaw.HAConfig { for { c, err := e.HAConfig() switch { case err != nil: log.Errorf("config: Failed to retrieve HAConfig: %v", err) case !c.Enabled: log.Infof("config: HA peering is currently disabled for this node") default: return c } time.Sleep(*initConfigRetryDelay) } }
go
func config(e ha.Engine) *seesaw.HAConfig { for { c, err := e.HAConfig() switch { case err != nil: log.Errorf("config: Failed to retrieve HAConfig: %v", err) case !c.Enabled: log.Infof("config: HA peering is currently disabled for this node") default: return c } time.Sleep(*initConfigRetryDelay) } }
[ "func", "config", "(", "e", "ha", ".", "Engine", ")", "*", "seesaw", ".", "HAConfig", "{", "for", "{", "c", ",", "err", ":=", "e", ".", "HAConfig", "(", ")", "\n", "switch", "{", "case", "err", "!=", "nil", ":", "log", ".", "Errorf", "(", "\"config: Failed to retrieve HAConfig: %v\"", ",", "err", ")", "\n", "case", "!", "c", ".", "Enabled", ":", "log", ".", "Infof", "(", "\"config: HA peering is currently disabled for this node\"", ")", "\n", "default", ":", "return", "c", "\n", "}", "\n", "time", ".", "Sleep", "(", "*", "initConfigRetryDelay", ")", "\n", "}", "\n", "}" ]
// config reads the HAConfig from the engine. It does not return until it // successfully retrieves an HAConfig that has HA peering enabled.
[ "config", "reads", "the", "HAConfig", "from", "the", "engine", ".", "It", "does", "not", "return", "until", "it", "successfully", "retrieves", "an", "HAConfig", "that", "has", "HA", "peering", "enabled", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/binaries/seesaw_ha/main.go#L81-L96
train
google/seesaw
engine/bgp.go
newBGPManager
func newBGPManager(engine *Engine, interval time.Duration) *bgpManager { return &bgpManager{engine: engine, updateInterval: interval} }
go
func newBGPManager(engine *Engine, interval time.Duration) *bgpManager { return &bgpManager{engine: engine, updateInterval: interval} }
[ "func", "newBGPManager", "(", "engine", "*", "Engine", ",", "interval", "time", ".", "Duration", ")", "*", "bgpManager", "{", "return", "&", "bgpManager", "{", "engine", ":", "engine", ",", "updateInterval", ":", "interval", "}", "\n", "}" ]
// newBGPManager returns an initialised bgpManager struct.
[ "newBGPManager", "returns", "an", "initialised", "bgpManager", "struct", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/bgp.go#L41-L43
train
google/seesaw
engine/bgp.go
run
func (b *bgpManager) run() { ticker := time.NewTicker(b.updateInterval) for { log.V(1).Infof("Updating BGP state and statistics...") b.update() <-ticker.C } }
go
func (b *bgpManager) run() { ticker := time.NewTicker(b.updateInterval) for { log.V(1).Infof("Updating BGP state and statistics...") b.update() <-ticker.C } }
[ "func", "(", "b", "*", "bgpManager", ")", "run", "(", ")", "{", "ticker", ":=", "time", ".", "NewTicker", "(", "b", ".", "updateInterval", ")", "\n", "for", "{", "log", ".", "V", "(", "1", ")", ".", "Infof", "(", "\"Updating BGP state and statistics...\"", ")", "\n", "b", ".", "update", "(", ")", "\n", "<-", "ticker", ".", "C", "\n", "}", "\n", "}" ]
// run runs the BGP configuration manager.
[ "run", "runs", "the", "BGP", "configuration", "manager", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/bgp.go#L46-L53
train
google/seesaw
engine/bgp.go
update
func (b *bgpManager) update() { ncc := b.engine.ncc if err := ncc.Dial(); err != nil { log.Warningf("BGP manager failed to connect to NCC: %v", err) return } defer ncc.Close() neighbors, err := ncc.BGPNeighbors() if err != nil { log.Warningf("Failed to get BGP neighbors: %v", err) return } b.lock.Lock() b.neighbors = neighbors b.lock.Unlock() }
go
func (b *bgpManager) update() { ncc := b.engine.ncc if err := ncc.Dial(); err != nil { log.Warningf("BGP manager failed to connect to NCC: %v", err) return } defer ncc.Close() neighbors, err := ncc.BGPNeighbors() if err != nil { log.Warningf("Failed to get BGP neighbors: %v", err) return } b.lock.Lock() b.neighbors = neighbors b.lock.Unlock() }
[ "func", "(", "b", "*", "bgpManager", ")", "update", "(", ")", "{", "ncc", ":=", "b", ".", "engine", ".", "ncc", "\n", "if", "err", ":=", "ncc", ".", "Dial", "(", ")", ";", "err", "!=", "nil", "{", "log", ".", "Warningf", "(", "\"BGP manager failed to connect to NCC: %v\"", ",", "err", ")", "\n", "return", "\n", "}", "\n", "defer", "ncc", ".", "Close", "(", ")", "\n", "neighbors", ",", "err", ":=", "ncc", ".", "BGPNeighbors", "(", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Warningf", "(", "\"Failed to get BGP neighbors: %v\"", ",", "err", ")", "\n", "return", "\n", "}", "\n", "b", ".", "lock", ".", "Lock", "(", ")", "\n", "b", ".", "neighbors", "=", "neighbors", "\n", "b", ".", "lock", ".", "Unlock", "(", ")", "\n", "}" ]
// update updates BGP related state and statistics from the BGP daemon.
[ "update", "updates", "BGP", "related", "state", "and", "statistics", "from", "the", "BGP", "daemon", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/bgp.go#L56-L72
train
google/seesaw
healthcheck/http.go
NewHTTPChecker
func NewHTTPChecker(ip net.IP, port int) *HTTPChecker { return &HTTPChecker{ Target: Target{ IP: ip, Port: port, Proto: seesaw.IPProtoTCP, }, Secure: false, TLSVerify: true, Method: "GET", Proxy: false, Request: "/", Response: "", ResponseCode: 200, } }
go
func NewHTTPChecker(ip net.IP, port int) *HTTPChecker { return &HTTPChecker{ Target: Target{ IP: ip, Port: port, Proto: seesaw.IPProtoTCP, }, Secure: false, TLSVerify: true, Method: "GET", Proxy: false, Request: "/", Response: "", ResponseCode: 200, } }
[ "func", "NewHTTPChecker", "(", "ip", "net", ".", "IP", ",", "port", "int", ")", "*", "HTTPChecker", "{", "return", "&", "HTTPChecker", "{", "Target", ":", "Target", "{", "IP", ":", "ip", ",", "Port", ":", "port", ",", "Proto", ":", "seesaw", ".", "IPProtoTCP", ",", "}", ",", "Secure", ":", "false", ",", "TLSVerify", ":", "true", ",", "Method", ":", "\"GET\"", ",", "Proxy", ":", "false", ",", "Request", ":", "\"/\"", ",", "Response", ":", "\"\"", ",", "ResponseCode", ":", "200", ",", "}", "\n", "}" ]
// NewHTTPChecker returns an initialised HTTPChecker.
[ "NewHTTPChecker", "returns", "an", "initialised", "HTTPChecker", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/http.go#L52-L67
train
google/seesaw
healthcheck/http.go
String
func (hc *HTTPChecker) String() string { attr := []string{fmt.Sprintf("code %d", hc.ResponseCode)} if hc.Proxy { attr = append(attr, "proxy") } if hc.Secure { attr = append(attr, "secure") if hc.TLSVerify { attr = append(attr, "verify") } } s := strings.Join(attr, "; ") return fmt.Sprintf("HTTP %s %s [%s] %s", hc.Method, hc.Request, s, hc.Target) }
go
func (hc *HTTPChecker) String() string { attr := []string{fmt.Sprintf("code %d", hc.ResponseCode)} if hc.Proxy { attr = append(attr, "proxy") } if hc.Secure { attr = append(attr, "secure") if hc.TLSVerify { attr = append(attr, "verify") } } s := strings.Join(attr, "; ") return fmt.Sprintf("HTTP %s %s [%s] %s", hc.Method, hc.Request, s, hc.Target) }
[ "func", "(", "hc", "*", "HTTPChecker", ")", "String", "(", ")", "string", "{", "attr", ":=", "[", "]", "string", "{", "fmt", ".", "Sprintf", "(", "\"code %d\"", ",", "hc", ".", "ResponseCode", ")", "}", "\n", "if", "hc", ".", "Proxy", "{", "attr", "=", "append", "(", "attr", ",", "\"proxy\"", ")", "\n", "}", "\n", "if", "hc", ".", "Secure", "{", "attr", "=", "append", "(", "attr", ",", "\"secure\"", ")", "\n", "if", "hc", ".", "TLSVerify", "{", "attr", "=", "append", "(", "attr", ",", "\"verify\"", ")", "\n", "}", "\n", "}", "\n", "s", ":=", "strings", ".", "Join", "(", "attr", ",", "\"; \"", ")", "\n", "return", "fmt", ".", "Sprintf", "(", "\"HTTP %s %s [%s] %s\"", ",", "hc", ".", "Method", ",", "hc", ".", "Request", ",", "s", ",", "hc", ".", "Target", ")", "\n", "}" ]
// String returns the string representation of an HTTP healthcheck.
[ "String", "returns", "the", "string", "representation", "of", "an", "HTTP", "healthcheck", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/http.go#L70-L83
train
google/seesaw
healthcheck/tcp.go
NewTCPChecker
func NewTCPChecker(ip net.IP, port int) *TCPChecker { return &TCPChecker{ Target: Target{ IP: ip, Port: port, Proto: seesaw.IPProtoTCP, }, } }
go
func NewTCPChecker(ip net.IP, port int) *TCPChecker { return &TCPChecker{ Target: Target{ IP: ip, Port: port, Proto: seesaw.IPProtoTCP, }, } }
[ "func", "NewTCPChecker", "(", "ip", "net", ".", "IP", ",", "port", "int", ")", "*", "TCPChecker", "{", "return", "&", "TCPChecker", "{", "Target", ":", "Target", "{", "IP", ":", "ip", ",", "Port", ":", "port", ",", "Proto", ":", "seesaw", ".", "IPProtoTCP", ",", "}", ",", "}", "\n", "}" ]
// NewTCPChecker returns an initialised TCPChecker.
[ "NewTCPChecker", "returns", "an", "initialised", "TCPChecker", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/tcp.go#L46-L54
train
google/seesaw
healthcheck/tcp.go
String
func (hc *TCPChecker) String() string { attr := []string{} if hc.Secure { attr = append(attr, "secure") if hc.TLSVerify { attr = append(attr, "verify") } } var s string if len(attr) > 0 { s = fmt.Sprintf(" [%s]", strings.Join(attr, "; ")) } return fmt.Sprintf("TCP%s %s", s, hc.Target) }
go
func (hc *TCPChecker) String() string { attr := []string{} if hc.Secure { attr = append(attr, "secure") if hc.TLSVerify { attr = append(attr, "verify") } } var s string if len(attr) > 0 { s = fmt.Sprintf(" [%s]", strings.Join(attr, "; ")) } return fmt.Sprintf("TCP%s %s", s, hc.Target) }
[ "func", "(", "hc", "*", "TCPChecker", ")", "String", "(", ")", "string", "{", "attr", ":=", "[", "]", "string", "{", "}", "\n", "if", "hc", ".", "Secure", "{", "attr", "=", "append", "(", "attr", ",", "\"secure\"", ")", "\n", "if", "hc", ".", "TLSVerify", "{", "attr", "=", "append", "(", "attr", ",", "\"verify\"", ")", "\n", "}", "\n", "}", "\n", "var", "s", "string", "\n", "if", "len", "(", "attr", ")", ">", "0", "{", "s", "=", "fmt", ".", "Sprintf", "(", "\" [%s]\"", ",", "strings", ".", "Join", "(", "attr", ",", "\"; \"", ")", ")", "\n", "}", "\n", "return", "fmt", ".", "Sprintf", "(", "\"TCP%s %s\"", ",", "s", ",", "hc", ".", "Target", ")", "\n", "}" ]
// String returns the string representation of a TCP healthcheck.
[ "String", "returns", "the", "string", "representation", "of", "a", "TCP", "healthcheck", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/tcp.go#L57-L70
train
google/seesaw
healthcheck/tcp.go
Check
func (hc *TCPChecker) Check(timeout time.Duration) *Result { msg := fmt.Sprintf("TCP connect to %s", hc.addr()) start := time.Now() if timeout == time.Duration(0) { timeout = defaultTCPTimeout } deadline := start.Add(timeout) tcpConn, err := dialTCP(hc.network(), hc.addr(), timeout, hc.Mark) if err != nil { msg = fmt.Sprintf("%s; failed to connect", msg) return complete(start, msg, false, err) } conn := net.Conn(tcpConn) defer conn.Close() // Negotiate TLS if this is required. if hc.Secure { // TODO(jsing): We probably should allow the server name to // be specified via configuration... host, _, err := net.SplitHostPort(hc.addr()) if err != nil { msg = msg + "; failed to split host" return complete(start, msg, false, err) } tlsConfig := &tls.Config{ InsecureSkipVerify: !hc.TLSVerify, ServerName: host, } tlsConn := tls.Client(conn, tlsConfig) if err := tlsConn.Handshake(); err != nil { return complete(start, msg, false, err) } conn = tlsConn } if hc.Send == "" && hc.Receive == "" { return complete(start, msg, true, err) } err = conn.SetDeadline(deadline) if err != nil { msg = fmt.Sprintf("%s; failed to set deadline", msg) return complete(start, msg, false, err) } if hc.Send != "" { err = writeFull(conn, []byte(hc.Send)) if err != nil { msg = fmt.Sprintf("%s; failed to send request", msg) return complete(start, msg, false, err) } } if hc.Receive != "" { buf := make([]byte, len(hc.Receive)) n, err := io.ReadFull(conn, buf) if err != nil { msg = fmt.Sprintf("%s; failed to read response", msg) return complete(start, msg, false, err) } got := string(buf[0:n]) if got != hc.Receive { msg = fmt.Sprintf("%s; unexpected response - %q", msg, got) return complete(start, msg, false, err) } } return complete(start, msg, true, err) }
go
func (hc *TCPChecker) Check(timeout time.Duration) *Result { msg := fmt.Sprintf("TCP connect to %s", hc.addr()) start := time.Now() if timeout == time.Duration(0) { timeout = defaultTCPTimeout } deadline := start.Add(timeout) tcpConn, err := dialTCP(hc.network(), hc.addr(), timeout, hc.Mark) if err != nil { msg = fmt.Sprintf("%s; failed to connect", msg) return complete(start, msg, false, err) } conn := net.Conn(tcpConn) defer conn.Close() // Negotiate TLS if this is required. if hc.Secure { // TODO(jsing): We probably should allow the server name to // be specified via configuration... host, _, err := net.SplitHostPort(hc.addr()) if err != nil { msg = msg + "; failed to split host" return complete(start, msg, false, err) } tlsConfig := &tls.Config{ InsecureSkipVerify: !hc.TLSVerify, ServerName: host, } tlsConn := tls.Client(conn, tlsConfig) if err := tlsConn.Handshake(); err != nil { return complete(start, msg, false, err) } conn = tlsConn } if hc.Send == "" && hc.Receive == "" { return complete(start, msg, true, err) } err = conn.SetDeadline(deadline) if err != nil { msg = fmt.Sprintf("%s; failed to set deadline", msg) return complete(start, msg, false, err) } if hc.Send != "" { err = writeFull(conn, []byte(hc.Send)) if err != nil { msg = fmt.Sprintf("%s; failed to send request", msg) return complete(start, msg, false, err) } } if hc.Receive != "" { buf := make([]byte, len(hc.Receive)) n, err := io.ReadFull(conn, buf) if err != nil { msg = fmt.Sprintf("%s; failed to read response", msg) return complete(start, msg, false, err) } got := string(buf[0:n]) if got != hc.Receive { msg = fmt.Sprintf("%s; unexpected response - %q", msg, got) return complete(start, msg, false, err) } } return complete(start, msg, true, err) }
[ "func", "(", "hc", "*", "TCPChecker", ")", "Check", "(", "timeout", "time", ".", "Duration", ")", "*", "Result", "{", "msg", ":=", "fmt", ".", "Sprintf", "(", "\"TCP connect to %s\"", ",", "hc", ".", "addr", "(", ")", ")", "\n", "start", ":=", "time", ".", "Now", "(", ")", "\n", "if", "timeout", "==", "time", ".", "Duration", "(", "0", ")", "{", "timeout", "=", "defaultTCPTimeout", "\n", "}", "\n", "deadline", ":=", "start", ".", "Add", "(", "timeout", ")", "\n", "tcpConn", ",", "err", ":=", "dialTCP", "(", "hc", ".", "network", "(", ")", ",", "hc", ".", "addr", "(", ")", ",", "timeout", ",", "hc", ".", "Mark", ")", "\n", "if", "err", "!=", "nil", "{", "msg", "=", "fmt", ".", "Sprintf", "(", "\"%s; failed to connect\"", ",", "msg", ")", "\n", "return", "complete", "(", "start", ",", "msg", ",", "false", ",", "err", ")", "\n", "}", "\n", "conn", ":=", "net", ".", "Conn", "(", "tcpConn", ")", "\n", "defer", "conn", ".", "Close", "(", ")", "\n", "if", "hc", ".", "Secure", "{", "host", ",", "_", ",", "err", ":=", "net", ".", "SplitHostPort", "(", "hc", ".", "addr", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "msg", "=", "msg", "+", "\"; failed to split host\"", "\n", "return", "complete", "(", "start", ",", "msg", ",", "false", ",", "err", ")", "\n", "}", "\n", "tlsConfig", ":=", "&", "tls", ".", "Config", "{", "InsecureSkipVerify", ":", "!", "hc", ".", "TLSVerify", ",", "ServerName", ":", "host", ",", "}", "\n", "tlsConn", ":=", "tls", ".", "Client", "(", "conn", ",", "tlsConfig", ")", "\n", "if", "err", ":=", "tlsConn", ".", "Handshake", "(", ")", ";", "err", "!=", "nil", "{", "return", "complete", "(", "start", ",", "msg", ",", "false", ",", "err", ")", "\n", "}", "\n", "conn", "=", "tlsConn", "\n", "}", "\n", "if", "hc", ".", "Send", "==", "\"\"", "&&", "hc", ".", "Receive", "==", "\"\"", "{", "return", "complete", "(", "start", ",", "msg", ",", "true", ",", "err", ")", "\n", "}", "\n", "err", "=", "conn", ".", "SetDeadline", "(", "deadline", ")", "\n", "if", "err", "!=", "nil", "{", "msg", "=", "fmt", ".", "Sprintf", "(", "\"%s; failed to set deadline\"", ",", "msg", ")", "\n", "return", "complete", "(", "start", ",", "msg", ",", "false", ",", "err", ")", "\n", "}", "\n", "if", "hc", ".", "Send", "!=", "\"\"", "{", "err", "=", "writeFull", "(", "conn", ",", "[", "]", "byte", "(", "hc", ".", "Send", ")", ")", "\n", "if", "err", "!=", "nil", "{", "msg", "=", "fmt", ".", "Sprintf", "(", "\"%s; failed to send request\"", ",", "msg", ")", "\n", "return", "complete", "(", "start", ",", "msg", ",", "false", ",", "err", ")", "\n", "}", "\n", "}", "\n", "if", "hc", ".", "Receive", "!=", "\"\"", "{", "buf", ":=", "make", "(", "[", "]", "byte", ",", "len", "(", "hc", ".", "Receive", ")", ")", "\n", "n", ",", "err", ":=", "io", ".", "ReadFull", "(", "conn", ",", "buf", ")", "\n", "if", "err", "!=", "nil", "{", "msg", "=", "fmt", ".", "Sprintf", "(", "\"%s; failed to read response\"", ",", "msg", ")", "\n", "return", "complete", "(", "start", ",", "msg", ",", "false", ",", "err", ")", "\n", "}", "\n", "got", ":=", "string", "(", "buf", "[", "0", ":", "n", "]", ")", "\n", "if", "got", "!=", "hc", ".", "Receive", "{", "msg", "=", "fmt", ".", "Sprintf", "(", "\"%s; unexpected response - %q\"", ",", "msg", ",", "got", ")", "\n", "return", "complete", "(", "start", ",", "msg", ",", "false", ",", "err", ")", "\n", "}", "\n", "}", "\n", "return", "complete", "(", "start", ",", "msg", ",", "true", ",", "err", ")", "\n", "}" ]
// Check executes a TCP healthcheck.
[ "Check", "executes", "a", "TCP", "healthcheck", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/tcp.go#L73-L141
train
google/seesaw
ncc/types/ncc_types.go
Interface
func (lb *LBInterface) Interface() (*net.Interface, error) { iface, err := net.InterfaceByName(lb.Name) if err != nil { return nil, err } return iface, nil }
go
func (lb *LBInterface) Interface() (*net.Interface, error) { iface, err := net.InterfaceByName(lb.Name) if err != nil { return nil, err } return iface, nil }
[ "func", "(", "lb", "*", "LBInterface", ")", "Interface", "(", ")", "(", "*", "net", ".", "Interface", ",", "error", ")", "{", "iface", ",", "err", ":=", "net", ".", "InterfaceByName", "(", "lb", ".", "Name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "iface", ",", "nil", "\n", "}" ]
// Interface returns the network interface associated with the LBInterface.
[ "Interface", "returns", "the", "network", "interface", "associated", "with", "the", "LBInterface", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/types/ncc_types.go#L73-L79
train
google/seesaw
cli/show.go
label
func label(l string, indent, width int) string { pad := width - indent - len(l) if pad < 0 { pad = 0 } return fmt.Sprintf("%s%s%s", strings.Repeat(" ", indent), l, strings.Repeat(" ", pad)) }
go
func label(l string, indent, width int) string { pad := width - indent - len(l) if pad < 0 { pad = 0 } return fmt.Sprintf("%s%s%s", strings.Repeat(" ", indent), l, strings.Repeat(" ", pad)) }
[ "func", "label", "(", "l", "string", ",", "indent", ",", "width", "int", ")", "string", "{", "pad", ":=", "width", "-", "indent", "-", "len", "(", "l", ")", "\n", "if", "pad", "<", "0", "{", "pad", "=", "0", "\n", "}", "\n", "return", "fmt", ".", "Sprintf", "(", "\"%s%s%s\"", ",", "strings", ".", "Repeat", "(", "\" \"", ",", "indent", ")", ",", "l", ",", "strings", ".", "Repeat", "(", "\" \"", ",", "pad", ")", ")", "\n", "}" ]
// label returns a string containing the label with indentation and padding.
[ "label", "returns", "a", "string", "containing", "the", "label", "with", "indentation", "and", "padding", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/cli/show.go#L554-L561
train
google/seesaw
cli/show.go
printFmt
func printFmt(l, v string, args ...interface{}) { l = label(l, subIndent, valIndent) fmt.Printf("%s %s\n", l, fmt.Sprintf(v, args...)) }
go
func printFmt(l, v string, args ...interface{}) { l = label(l, subIndent, valIndent) fmt.Printf("%s %s\n", l, fmt.Sprintf(v, args...)) }
[ "func", "printFmt", "(", "l", ",", "v", "string", ",", "args", "...", "interface", "{", "}", ")", "{", "l", "=", "label", "(", "l", ",", "subIndent", ",", "valIndent", ")", "\n", "fmt", ".", "Printf", "(", "\"%s %s\\n\"", ",", "\\n", ",", "l", ")", "\n", "}" ]
// printFmt formats and prints a given value with the specified label.
[ "printFmt", "formats", "and", "prints", "a", "given", "value", "with", "the", "specified", "label", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/cli/show.go#L569-L572
train
google/seesaw
cli/show.go
printVal
func printVal(l string, v interface{}) { switch f := v.(type) { case uint, uint64: printFmt(l, "%d", f) case string: printFmt(l, "%s", f) default: printFmt(l, "%v", f) } }
go
func printVal(l string, v interface{}) { switch f := v.(type) { case uint, uint64: printFmt(l, "%d", f) case string: printFmt(l, "%s", f) default: printFmt(l, "%v", f) } }
[ "func", "printVal", "(", "l", "string", ",", "v", "interface", "{", "}", ")", "{", "switch", "f", ":=", "v", ".", "(", "type", ")", "{", "case", "uint", ",", "uint64", ":", "printFmt", "(", "l", ",", "\"%d\"", ",", "f", ")", "\n", "case", "string", ":", "printFmt", "(", "l", ",", "\"%s\"", ",", "f", ")", "\n", "default", ":", "printFmt", "(", "l", ",", "\"%v\"", ",", "f", ")", "\n", "}", "\n", "}" ]
// printVal prints the given value with the specified label.
[ "printVal", "prints", "the", "given", "value", "with", "the", "specified", "label", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/cli/show.go#L575-L584
train
google/seesaw
engine/sync.go
String
func (snt SyncNoteType) String() string { if name, ok := syncNoteTypeNames[snt]; ok { return name } return fmt.Sprintf("(Unknown %d)", snt) }
go
func (snt SyncNoteType) String() string { if name, ok := syncNoteTypeNames[snt]; ok { return name } return fmt.Sprintf("(Unknown %d)", snt) }
[ "func", "(", "snt", "SyncNoteType", ")", "String", "(", ")", "string", "{", "if", "name", ",", "ok", ":=", "syncNoteTypeNames", "[", "snt", "]", ";", "ok", "{", "return", "name", "\n", "}", "\n", "return", "fmt", ".", "Sprintf", "(", "\"(Unknown %d)\"", ",", "snt", ")", "\n", "}" ]
// String returns the string representation of a synchronisation notification // type.
[ "String", "returns", "the", "string", "representation", "of", "a", "synchronisation", "notification", "type", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/sync.go#L73-L78
train
google/seesaw
engine/sync.go
Register
func (s *SeesawSync) Register(node net.IP, id *SyncSessionID) error { if id == nil { return errors.New("id is nil") } // TODO(jsing): Reject if not master? s.sync.sessionLock.Lock() session := newSyncSession(node, s.sync.nextSessionID) s.sync.nextSessionID++ s.sync.sessions[session.id] = session s.sync.sessionLock.Unlock() session.Lock() session.expiryTime = time.Now().Add(sessionDeadtime) session.Unlock() *id = session.id log.Infof("Synchronisation session %d registered by %v", *id, node) return nil }
go
func (s *SeesawSync) Register(node net.IP, id *SyncSessionID) error { if id == nil { return errors.New("id is nil") } // TODO(jsing): Reject if not master? s.sync.sessionLock.Lock() session := newSyncSession(node, s.sync.nextSessionID) s.sync.nextSessionID++ s.sync.sessions[session.id] = session s.sync.sessionLock.Unlock() session.Lock() session.expiryTime = time.Now().Add(sessionDeadtime) session.Unlock() *id = session.id log.Infof("Synchronisation session %d registered by %v", *id, node) return nil }
[ "func", "(", "s", "*", "SeesawSync", ")", "Register", "(", "node", "net", ".", "IP", ",", "id", "*", "SyncSessionID", ")", "error", "{", "if", "id", "==", "nil", "{", "return", "errors", ".", "New", "(", "\"id is nil\"", ")", "\n", "}", "\n", "s", ".", "sync", ".", "sessionLock", ".", "Lock", "(", ")", "\n", "session", ":=", "newSyncSession", "(", "node", ",", "s", ".", "sync", ".", "nextSessionID", ")", "\n", "s", ".", "sync", ".", "nextSessionID", "++", "\n", "s", ".", "sync", ".", "sessions", "[", "session", ".", "id", "]", "=", "session", "\n", "s", ".", "sync", ".", "sessionLock", ".", "Unlock", "(", ")", "\n", "session", ".", "Lock", "(", ")", "\n", "session", ".", "expiryTime", "=", "time", ".", "Now", "(", ")", ".", "Add", "(", "sessionDeadtime", ")", "\n", "session", ".", "Unlock", "(", ")", "\n", "*", "id", "=", "session", ".", "id", "\n", "log", ".", "Infof", "(", "\"Synchronisation session %d registered by %v\"", ",", "*", "id", ",", "node", ")", "\n", "return", "nil", "\n", "}" ]
// Register registers our Seesaw peer for synchronisation notifications.
[ "Register", "registers", "our", "Seesaw", "peer", "for", "synchronisation", "notifications", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/sync.go#L103-L125
train
google/seesaw
engine/sync.go
Deregister
func (s *SeesawSync) Deregister(id SyncSessionID, reply *int) error { s.sync.sessionLock.Lock() session, ok := s.sync.sessions[id] delete(s.sync.sessions, id) s.sync.sessionLock.Unlock() if ok { log.Infof("Synchronisation session %d deregistered with %v", id, session.node) } return nil }
go
func (s *SeesawSync) Deregister(id SyncSessionID, reply *int) error { s.sync.sessionLock.Lock() session, ok := s.sync.sessions[id] delete(s.sync.sessions, id) s.sync.sessionLock.Unlock() if ok { log.Infof("Synchronisation session %d deregistered with %v", id, session.node) } return nil }
[ "func", "(", "s", "*", "SeesawSync", ")", "Deregister", "(", "id", "SyncSessionID", ",", "reply", "*", "int", ")", "error", "{", "s", ".", "sync", ".", "sessionLock", ".", "Lock", "(", ")", "\n", "session", ",", "ok", ":=", "s", ".", "sync", ".", "sessions", "[", "id", "]", "\n", "delete", "(", "s", ".", "sync", ".", "sessions", ",", "id", ")", "\n", "s", ".", "sync", ".", "sessionLock", ".", "Unlock", "(", ")", "\n", "if", "ok", "{", "log", ".", "Infof", "(", "\"Synchronisation session %d deregistered with %v\"", ",", "id", ",", "session", ".", "node", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Deregister deregisters a Seesaw peer for synchronisation.
[ "Deregister", "deregisters", "a", "Seesaw", "peer", "for", "synchronisation", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/sync.go#L128-L139
train
google/seesaw
engine/sync.go
Poll
func (s *SeesawSync) Poll(id SyncSessionID, sn *SyncNotes) error { if sn == nil { return errors.New("sync notes is nil") } s.sync.sessionLock.RLock() session, ok := s.sync.sessions[id] s.sync.sessionLock.RUnlock() if !ok { return errors.New("no session with ID %d") } // Reset expiry time and check for desynchronisation. session.Lock() session.expiryTime = time.Now().Add(sessionDeadtime) if session.desync { // TODO(jsing): Discard pending notes? sn.Notes = append(sn.Notes, SyncNote{Type: SNTDesync}) session.desync = false session.Unlock() return nil } session.Unlock() // Block until a notification becomes available or our poll expires. select { case note := <-session.notes: sn.Notes = append(sn.Notes, *note) case <-time.After(syncPollTimeout): return errors.New("poll timeout") } pollLoop: for i := 0; i < syncPollMsgLimit; i++ { select { case note := <-session.notes: sn.Notes = append(sn.Notes, *note) default: break pollLoop } } log.V(1).Infof("Sync server poll returning %d notifications", len(sn.Notes)) return nil }
go
func (s *SeesawSync) Poll(id SyncSessionID, sn *SyncNotes) error { if sn == nil { return errors.New("sync notes is nil") } s.sync.sessionLock.RLock() session, ok := s.sync.sessions[id] s.sync.sessionLock.RUnlock() if !ok { return errors.New("no session with ID %d") } // Reset expiry time and check for desynchronisation. session.Lock() session.expiryTime = time.Now().Add(sessionDeadtime) if session.desync { // TODO(jsing): Discard pending notes? sn.Notes = append(sn.Notes, SyncNote{Type: SNTDesync}) session.desync = false session.Unlock() return nil } session.Unlock() // Block until a notification becomes available or our poll expires. select { case note := <-session.notes: sn.Notes = append(sn.Notes, *note) case <-time.After(syncPollTimeout): return errors.New("poll timeout") } pollLoop: for i := 0; i < syncPollMsgLimit; i++ { select { case note := <-session.notes: sn.Notes = append(sn.Notes, *note) default: break pollLoop } } log.V(1).Infof("Sync server poll returning %d notifications", len(sn.Notes)) return nil }
[ "func", "(", "s", "*", "SeesawSync", ")", "Poll", "(", "id", "SyncSessionID", ",", "sn", "*", "SyncNotes", ")", "error", "{", "if", "sn", "==", "nil", "{", "return", "errors", ".", "New", "(", "\"sync notes is nil\"", ")", "\n", "}", "\n", "s", ".", "sync", ".", "sessionLock", ".", "RLock", "(", ")", "\n", "session", ",", "ok", ":=", "s", ".", "sync", ".", "sessions", "[", "id", "]", "\n", "s", ".", "sync", ".", "sessionLock", ".", "RUnlock", "(", ")", "\n", "if", "!", "ok", "{", "return", "errors", ".", "New", "(", "\"no session with ID %d\"", ")", "\n", "}", "\n", "session", ".", "Lock", "(", ")", "\n", "session", ".", "expiryTime", "=", "time", ".", "Now", "(", ")", ".", "Add", "(", "sessionDeadtime", ")", "\n", "if", "session", ".", "desync", "{", "sn", ".", "Notes", "=", "append", "(", "sn", ".", "Notes", ",", "SyncNote", "{", "Type", ":", "SNTDesync", "}", ")", "\n", "session", ".", "desync", "=", "false", "\n", "session", ".", "Unlock", "(", ")", "\n", "return", "nil", "\n", "}", "\n", "session", ".", "Unlock", "(", ")", "\n", "select", "{", "case", "note", ":=", "<-", "session", ".", "notes", ":", "sn", ".", "Notes", "=", "append", "(", "sn", ".", "Notes", ",", "*", "note", ")", "\n", "case", "<-", "time", ".", "After", "(", "syncPollTimeout", ")", ":", "return", "errors", ".", "New", "(", "\"poll timeout\"", ")", "\n", "}", "\n", "pollLoop", ":", "for", "i", ":=", "0", ";", "i", "<", "syncPollMsgLimit", ";", "i", "++", "{", "select", "{", "case", "note", ":=", "<-", "session", ".", "notes", ":", "sn", ".", "Notes", "=", "append", "(", "sn", ".", "Notes", ",", "*", "note", ")", "\n", "default", ":", "break", "pollLoop", "\n", "}", "\n", "}", "\n", "log", ".", "V", "(", "1", ")", ".", "Infof", "(", "\"Sync server poll returning %d notifications\"", ",", "len", "(", "sn", ".", "Notes", ")", ")", "\n", "return", "nil", "\n", "}" ]
// Poll returns one or more synchronisation notifications to the caller, // blocking until at least one notification becomes available or the poll // timeout is reached.
[ "Poll", "returns", "one", "or", "more", "synchronisation", "notifications", "to", "the", "caller", "blocking", "until", "at", "least", "one", "notification", "becomes", "available", "or", "the", "poll", "timeout", "is", "reached", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/sync.go#L144-L188
train
google/seesaw
engine/sync.go
Config
func (s *SeesawSync) Config(arg int, config *config.Notification) error { return errors.New("unimplemented") }
go
func (s *SeesawSync) Config(arg int, config *config.Notification) error { return errors.New("unimplemented") }
[ "func", "(", "s", "*", "SeesawSync", ")", "Config", "(", "arg", "int", ",", "config", "*", "config", ".", "Notification", ")", "error", "{", "return", "errors", ".", "New", "(", "\"unimplemented\"", ")", "\n", "}" ]
// Config requests the current configuration from the peer Seesaw node.
[ "Config", "requests", "the", "current", "configuration", "from", "the", "peer", "Seesaw", "node", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/sync.go#L191-L193
train
google/seesaw
engine/sync.go
Failover
func (s *SeesawSync) Failover(arg int, reply *int) error { return s.sync.engine.haManager.requestFailover(true) }
go
func (s *SeesawSync) Failover(arg int, reply *int) error { return s.sync.engine.haManager.requestFailover(true) }
[ "func", "(", "s", "*", "SeesawSync", ")", "Failover", "(", "arg", "int", ",", "reply", "*", "int", ")", "error", "{", "return", "s", ".", "sync", ".", "engine", ".", "haManager", ".", "requestFailover", "(", "true", ")", "\n", "}" ]
// Failover requests that we relinquish master state.
[ "Failover", "requests", "that", "we", "relinquish", "master", "state", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/sync.go#L196-L198
train
google/seesaw
engine/sync.go
Healthchecks
func (s *SeesawSync) Healthchecks(arg int, reply *int) error { return errors.New("unimplemented") }
go
func (s *SeesawSync) Healthchecks(arg int, reply *int) error { return errors.New("unimplemented") }
[ "func", "(", "s", "*", "SeesawSync", ")", "Healthchecks", "(", "arg", "int", ",", "reply", "*", "int", ")", "error", "{", "return", "errors", ".", "New", "(", "\"unimplemented\"", ")", "\n", "}" ]
// Healthchecks requests the current healthchecks from the peer Seesaw node.
[ "Healthchecks", "requests", "the", "current", "healthchecks", "from", "the", "peer", "Seesaw", "node", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/sync.go#L201-L203
train
google/seesaw
engine/sync.go
newSyncSession
func newSyncSession(node net.IP, id SyncSessionID) *syncSession { return &syncSession{ id: id, node: node, desync: true, startTime: time.Now(), expiryTime: time.Now().Add(sessionDeadtime), notes: make(chan *SyncNote, sessionNotesQueueSize), } }
go
func newSyncSession(node net.IP, id SyncSessionID) *syncSession { return &syncSession{ id: id, node: node, desync: true, startTime: time.Now(), expiryTime: time.Now().Add(sessionDeadtime), notes: make(chan *SyncNote, sessionNotesQueueSize), } }
[ "func", "newSyncSession", "(", "node", "net", ".", "IP", ",", "id", "SyncSessionID", ")", "*", "syncSession", "{", "return", "&", "syncSession", "{", "id", ":", "id", ",", "node", ":", "node", ",", "desync", ":", "true", ",", "startTime", ":", "time", ".", "Now", "(", ")", ",", "expiryTime", ":", "time", ".", "Now", "(", ")", ".", "Add", "(", "sessionDeadtime", ")", ",", "notes", ":", "make", "(", "chan", "*", "SyncNote", ",", "sessionNotesQueueSize", ")", ",", "}", "\n", "}" ]
// newSyncSession returns an initialised synchronisation session.
[ "newSyncSession", "returns", "an", "initialised", "synchronisation", "session", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/sync.go#L218-L227
train
google/seesaw
engine/sync.go
addNote
func (ss *syncSession) addNote(note *SyncNote) { select { case ss.notes <- note: default: ss.Lock() if !ss.desync { log.Warningf("Sync session with %v is desynchronised", ss.node) ss.desync = true } ss.Unlock() } }
go
func (ss *syncSession) addNote(note *SyncNote) { select { case ss.notes <- note: default: ss.Lock() if !ss.desync { log.Warningf("Sync session with %v is desynchronised", ss.node) ss.desync = true } ss.Unlock() } }
[ "func", "(", "ss", "*", "syncSession", ")", "addNote", "(", "note", "*", "SyncNote", ")", "{", "select", "{", "case", "ss", ".", "notes", "<-", "note", ":", "default", ":", "ss", ".", "Lock", "(", ")", "\n", "if", "!", "ss", ".", "desync", "{", "log", ".", "Warningf", "(", "\"Sync session with %v is desynchronised\"", ",", "ss", ".", "node", ")", "\n", "ss", ".", "desync", "=", "true", "\n", "}", "\n", "ss", ".", "Unlock", "(", ")", "\n", "}", "\n", "}" ]
// addNote adds a notification to the synchronisation session. If the notes // channel is full the session is marked as desynchronised and the notification // is discarded.
[ "addNote", "adds", "a", "notification", "to", "the", "synchronisation", "session", ".", "If", "the", "notes", "channel", "is", "full", "the", "session", "is", "marked", "as", "desynchronised", "and", "the", "notification", "is", "discarded", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/sync.go#L232-L243
train
google/seesaw
engine/sync.go
newSyncServer
func newSyncServer(e *Engine) *syncServer { return &syncServer{ engine: e, heartbeatInterval: syncHeartbeatInterval, sessions: make(map[SyncSessionID]*syncSession), } }
go
func newSyncServer(e *Engine) *syncServer { return &syncServer{ engine: e, heartbeatInterval: syncHeartbeatInterval, sessions: make(map[SyncSessionID]*syncSession), } }
[ "func", "newSyncServer", "(", "e", "*", "Engine", ")", "*", "syncServer", "{", "return", "&", "syncServer", "{", "engine", ":", "e", ",", "heartbeatInterval", ":", "syncHeartbeatInterval", ",", "sessions", ":", "make", "(", "map", "[", "SyncSessionID", "]", "*", "syncSession", ")", ",", "}", "\n", "}" ]
// newSyncServer returns an initalised synchronisation server.
[ "newSyncServer", "returns", "an", "initalised", "synchronisation", "server", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/sync.go#L257-L263
train
google/seesaw
engine/sync.go
serve
func (s *syncServer) serve(l *net.TCPListener) error { defer l.Close() s.server = rpc.NewServer() s.server.Register(&SeesawSync{s}) for { c, err := l.AcceptTCP() if err != nil { if ne, ok := err.(net.Error); ok && ne.Temporary() { time.Sleep(100 * time.Millisecond) continue } return err } raddr := c.RemoteAddr().String() host, _, err := net.SplitHostPort(raddr) if err != nil { log.Errorf("Failed to parse remote address %q: %v", raddr, err) c.Close() continue } rip := net.ParseIP(host) if rip == nil || (!rip.IsLoopback() && !rip.Equal(s.engine.config.Peer.IPv4Addr) && !rip.Equal(s.engine.config.Peer.IPv6Addr)) { log.Warningf("Rejecting connection from non-peer (%s)...", rip) c.Close() continue } log.Infof("Sync connection established from %s", rip) go s.server.ServeConn(c) } }
go
func (s *syncServer) serve(l *net.TCPListener) error { defer l.Close() s.server = rpc.NewServer() s.server.Register(&SeesawSync{s}) for { c, err := l.AcceptTCP() if err != nil { if ne, ok := err.(net.Error); ok && ne.Temporary() { time.Sleep(100 * time.Millisecond) continue } return err } raddr := c.RemoteAddr().String() host, _, err := net.SplitHostPort(raddr) if err != nil { log.Errorf("Failed to parse remote address %q: %v", raddr, err) c.Close() continue } rip := net.ParseIP(host) if rip == nil || (!rip.IsLoopback() && !rip.Equal(s.engine.config.Peer.IPv4Addr) && !rip.Equal(s.engine.config.Peer.IPv6Addr)) { log.Warningf("Rejecting connection from non-peer (%s)...", rip) c.Close() continue } log.Infof("Sync connection established from %s", rip) go s.server.ServeConn(c) } }
[ "func", "(", "s", "*", "syncServer", ")", "serve", "(", "l", "*", "net", ".", "TCPListener", ")", "error", "{", "defer", "l", ".", "Close", "(", ")", "\n", "s", ".", "server", "=", "rpc", ".", "NewServer", "(", ")", "\n", "s", ".", "server", ".", "Register", "(", "&", "SeesawSync", "{", "s", "}", ")", "\n", "for", "{", "c", ",", "err", ":=", "l", ".", "AcceptTCP", "(", ")", "\n", "if", "err", "!=", "nil", "{", "if", "ne", ",", "ok", ":=", "err", ".", "(", "net", ".", "Error", ")", ";", "ok", "&&", "ne", ".", "Temporary", "(", ")", "{", "time", ".", "Sleep", "(", "100", "*", "time", ".", "Millisecond", ")", "\n", "continue", "\n", "}", "\n", "return", "err", "\n", "}", "\n", "raddr", ":=", "c", ".", "RemoteAddr", "(", ")", ".", "String", "(", ")", "\n", "host", ",", "_", ",", "err", ":=", "net", ".", "SplitHostPort", "(", "raddr", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"Failed to parse remote address %q: %v\"", ",", "raddr", ",", "err", ")", "\n", "c", ".", "Close", "(", ")", "\n", "continue", "\n", "}", "\n", "rip", ":=", "net", ".", "ParseIP", "(", "host", ")", "\n", "if", "rip", "==", "nil", "||", "(", "!", "rip", ".", "IsLoopback", "(", ")", "&&", "!", "rip", ".", "Equal", "(", "s", ".", "engine", ".", "config", ".", "Peer", ".", "IPv4Addr", ")", "&&", "!", "rip", ".", "Equal", "(", "s", ".", "engine", ".", "config", ".", "Peer", ".", "IPv6Addr", ")", ")", "{", "log", ".", "Warningf", "(", "\"Rejecting connection from non-peer (%s)...\"", ",", "rip", ")", "\n", "c", ".", "Close", "(", ")", "\n", "continue", "\n", "}", "\n", "log", ".", "Infof", "(", "\"Sync connection established from %s\"", ",", "rip", ")", "\n", "go", "s", ".", "server", ".", "ServeConn", "(", "c", ")", "\n", "}", "\n", "}" ]
// serve accepts connections from the given TCP listener and dispatches each // connection to the RPC server. Connections are only accepted from localhost // and the seesaw node that we are configured to peer with.
[ "serve", "accepts", "connections", "from", "the", "given", "TCP", "listener", "and", "dispatches", "each", "connection", "to", "the", "RPC", "server", ".", "Connections", "are", "only", "accepted", "from", "localhost", "and", "the", "seesaw", "node", "that", "we", "are", "configured", "to", "peer", "with", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/sync.go#L268-L299
train
google/seesaw
engine/sync.go
notify
func (s *syncServer) notify(sn *SyncNote) { s.sessionLock.RLock() sessions := s.sessions s.sessionLock.RUnlock() for _, ss := range sessions { ss.addNote(sn) } }
go
func (s *syncServer) notify(sn *SyncNote) { s.sessionLock.RLock() sessions := s.sessions s.sessionLock.RUnlock() for _, ss := range sessions { ss.addNote(sn) } }
[ "func", "(", "s", "*", "syncServer", ")", "notify", "(", "sn", "*", "SyncNote", ")", "{", "s", ".", "sessionLock", ".", "RLock", "(", ")", "\n", "sessions", ":=", "s", ".", "sessions", "\n", "s", ".", "sessionLock", ".", "RUnlock", "(", ")", "\n", "for", "_", ",", "ss", ":=", "range", "sessions", "{", "ss", ".", "addNote", "(", "sn", ")", "\n", "}", "\n", "}" ]
// notify queues a synchronisation notification with each of the active // synchronisation sessions.
[ "notify", "queues", "a", "synchronisation", "notification", "with", "each", "of", "the", "active", "synchronisation", "sessions", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/sync.go#L303-L310
train
google/seesaw
engine/sync.go
run
func (s *syncServer) run() error { heartbeat := time.NewTicker(s.heartbeatInterval) for { select { case <-heartbeat.C: now := time.Now() s.sessionLock.Lock() for id, ss := range s.sessions { ss.RLock() expiry := ss.expiryTime ss.RUnlock() if now.After(expiry) { log.Warningf("Sync session %d with %v has expired", id, ss.node) delete(s.sessions, id) continue } ss.addNote(&SyncNote{Type: SNTHeartbeat}) } s.sessionLock.Unlock() } } }
go
func (s *syncServer) run() error { heartbeat := time.NewTicker(s.heartbeatInterval) for { select { case <-heartbeat.C: now := time.Now() s.sessionLock.Lock() for id, ss := range s.sessions { ss.RLock() expiry := ss.expiryTime ss.RUnlock() if now.After(expiry) { log.Warningf("Sync session %d with %v has expired", id, ss.node) delete(s.sessions, id) continue } ss.addNote(&SyncNote{Type: SNTHeartbeat}) } s.sessionLock.Unlock() } } }
[ "func", "(", "s", "*", "syncServer", ")", "run", "(", ")", "error", "{", "heartbeat", ":=", "time", ".", "NewTicker", "(", "s", ".", "heartbeatInterval", ")", "\n", "for", "{", "select", "{", "case", "<-", "heartbeat", ".", "C", ":", "now", ":=", "time", ".", "Now", "(", ")", "\n", "s", ".", "sessionLock", ".", "Lock", "(", ")", "\n", "for", "id", ",", "ss", ":=", "range", "s", ".", "sessions", "{", "ss", ".", "RLock", "(", ")", "\n", "expiry", ":=", "ss", ".", "expiryTime", "\n", "ss", ".", "RUnlock", "(", ")", "\n", "if", "now", ".", "After", "(", "expiry", ")", "{", "log", ".", "Warningf", "(", "\"Sync session %d with %v has expired\"", ",", "id", ",", "ss", ".", "node", ")", "\n", "delete", "(", "s", ".", "sessions", ",", "id", ")", "\n", "continue", "\n", "}", "\n", "ss", ".", "addNote", "(", "&", "SyncNote", "{", "Type", ":", "SNTHeartbeat", "}", ")", "\n", "}", "\n", "s", ".", "sessionLock", ".", "Unlock", "(", ")", "\n", "}", "\n", "}", "\n", "}" ]
// run runs the synchronisation server, which is responsible for queueing // heartbeat notifications and removing expired synchronisation sessions.
[ "run", "runs", "the", "synchronisation", "server", "which", "is", "responsible", "for", "queueing", "heartbeat", "notifications", "and", "removing", "expired", "synchronisation", "sessions", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/sync.go#L314-L335
train
google/seesaw
engine/sync.go
newSyncClient
func newSyncClient(e *Engine) *syncClient { sc := &syncClient{ engine: e, quit: make(chan bool), start: make(chan bool), stopped: make(chan bool, 1), } sc.dispatch = sc.handleNote sc.stopped <- true return sc }
go
func newSyncClient(e *Engine) *syncClient { sc := &syncClient{ engine: e, quit: make(chan bool), start: make(chan bool), stopped: make(chan bool, 1), } sc.dispatch = sc.handleNote sc.stopped <- true return sc }
[ "func", "newSyncClient", "(", "e", "*", "Engine", ")", "*", "syncClient", "{", "sc", ":=", "&", "syncClient", "{", "engine", ":", "e", ",", "quit", ":", "make", "(", "chan", "bool", ")", ",", "start", ":", "make", "(", "chan", "bool", ")", ",", "stopped", ":", "make", "(", "chan", "bool", ",", "1", ")", ",", "}", "\n", "sc", ".", "dispatch", "=", "sc", ".", "handleNote", "\n", "sc", ".", "stopped", "<-", "true", "\n", "return", "sc", "\n", "}" ]
// newSyncClient returns an initialised synchronisation client.
[ "newSyncClient", "returns", "an", "initialised", "synchronisation", "client", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/sync.go#L354-L364
train
google/seesaw
engine/sync.go
dial
func (sc *syncClient) dial() error { sc.lock.Lock() defer sc.lock.Unlock() if sc.client != nil { sc.refs++ return nil } // TODO(jsing): Make this default to IPv6, if configured. peer := &net.TCPAddr{ IP: sc.engine.config.Peer.IPv4Addr, Port: sc.engine.config.SyncPort, } self := &net.TCPAddr{ IP: sc.engine.config.Node.IPv4Addr, } conn, err := net.DialTCP("tcp", self, peer) if err != nil { return fmt.Errorf("failed to connect: %v", err) } sc.client = rpc.NewClient(conn) sc.refs = 1 return nil }
go
func (sc *syncClient) dial() error { sc.lock.Lock() defer sc.lock.Unlock() if sc.client != nil { sc.refs++ return nil } // TODO(jsing): Make this default to IPv6, if configured. peer := &net.TCPAddr{ IP: sc.engine.config.Peer.IPv4Addr, Port: sc.engine.config.SyncPort, } self := &net.TCPAddr{ IP: sc.engine.config.Node.IPv4Addr, } conn, err := net.DialTCP("tcp", self, peer) if err != nil { return fmt.Errorf("failed to connect: %v", err) } sc.client = rpc.NewClient(conn) sc.refs = 1 return nil }
[ "func", "(", "sc", "*", "syncClient", ")", "dial", "(", ")", "error", "{", "sc", ".", "lock", ".", "Lock", "(", ")", "\n", "defer", "sc", ".", "lock", ".", "Unlock", "(", ")", "\n", "if", "sc", ".", "client", "!=", "nil", "{", "sc", ".", "refs", "++", "\n", "return", "nil", "\n", "}", "\n", "peer", ":=", "&", "net", ".", "TCPAddr", "{", "IP", ":", "sc", ".", "engine", ".", "config", ".", "Peer", ".", "IPv4Addr", ",", "Port", ":", "sc", ".", "engine", ".", "config", ".", "SyncPort", ",", "}", "\n", "self", ":=", "&", "net", ".", "TCPAddr", "{", "IP", ":", "sc", ".", "engine", ".", "config", ".", "Node", ".", "IPv4Addr", ",", "}", "\n", "conn", ",", "err", ":=", "net", ".", "DialTCP", "(", "\"tcp\"", ",", "self", ",", "peer", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"failed to connect: %v\"", ",", "err", ")", "\n", "}", "\n", "sc", ".", "client", "=", "rpc", ".", "NewClient", "(", "conn", ")", "\n", "sc", ".", "refs", "=", "1", "\n", "return", "nil", "\n", "}" ]
// dial establishes a connection to our peer Seesaw node.
[ "dial", "establishes", "a", "connection", "to", "our", "peer", "Seesaw", "node", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/sync.go#L367-L390
train
google/seesaw
engine/sync.go
close
func (sc *syncClient) close() error { sc.lock.Lock() defer sc.lock.Unlock() if sc.client == nil { return nil } sc.refs-- if sc.refs > 0 { return nil } if err := sc.client.Close(); err != nil { sc.client = nil return fmt.Errorf("client close failed: %v", err) } sc.client = nil return nil }
go
func (sc *syncClient) close() error { sc.lock.Lock() defer sc.lock.Unlock() if sc.client == nil { return nil } sc.refs-- if sc.refs > 0 { return nil } if err := sc.client.Close(); err != nil { sc.client = nil return fmt.Errorf("client close failed: %v", err) } sc.client = nil return nil }
[ "func", "(", "sc", "*", "syncClient", ")", "close", "(", ")", "error", "{", "sc", ".", "lock", ".", "Lock", "(", ")", "\n", "defer", "sc", ".", "lock", ".", "Unlock", "(", ")", "\n", "if", "sc", ".", "client", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "sc", ".", "refs", "--", "\n", "if", "sc", ".", "refs", ">", "0", "{", "return", "nil", "\n", "}", "\n", "if", "err", ":=", "sc", ".", "client", ".", "Close", "(", ")", ";", "err", "!=", "nil", "{", "sc", ".", "client", "=", "nil", "\n", "return", "fmt", ".", "Errorf", "(", "\"client close failed: %v\"", ",", "err", ")", "\n", "}", "\n", "sc", ".", "client", "=", "nil", "\n", "return", "nil", "\n", "}" ]
// close closes an existing connection to our peer Seesaw node.
[ "close", "closes", "an", "existing", "connection", "to", "our", "peer", "Seesaw", "node", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/sync.go#L393-L409
train
google/seesaw
engine/sync.go
failover
func (sc *syncClient) failover() error { if err := sc.dial(); err != nil { return err } defer sc.close() if err := sc.client.Call("SeesawSync.Failover", 0, nil); err != nil { return err } return nil }
go
func (sc *syncClient) failover() error { if err := sc.dial(); err != nil { return err } defer sc.close() if err := sc.client.Call("SeesawSync.Failover", 0, nil); err != nil { return err } return nil }
[ "func", "(", "sc", "*", "syncClient", ")", "failover", "(", ")", "error", "{", "if", "err", ":=", "sc", ".", "dial", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "sc", ".", "close", "(", ")", "\n", "if", "err", ":=", "sc", ".", "client", ".", "Call", "(", "\"SeesawSync.Failover\"", ",", "0", ",", "nil", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// failover requests that the peer node initiate a failover.
[ "failover", "requests", "that", "the", "peer", "node", "initiate", "a", "failover", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/sync.go#L412-L421
train
google/seesaw
engine/sync.go
runOnce
func (sc *syncClient) runOnce() { if err := sc.dial(); err != nil { log.Warningf("Sync client dial failed: %v", err) return } defer sc.close() var sid SyncSessionID self := sc.engine.config.Node.IPv4Addr // Register for synchronisation events. // TODO(jsing): Implement timeout on RPC? if err := sc.client.Call("SeesawSync.Register", self, &sid); err != nil { log.Warningf("Sync registration failed: %v", err) return } log.Infof("Registered for synchronisation notifications (ID %d)", sid) // TODO(jsing): Export synchronisation data to ECU/CLI. sc.poll(sid) // Attempt to deregister for notifications. // TODO(jsing): Implement timeout on RPC? if err := sc.client.Call("SeesawSync.Deregister", sid, nil); err != nil { log.Warningf("Sync deregistration failed: %v", err) } }
go
func (sc *syncClient) runOnce() { if err := sc.dial(); err != nil { log.Warningf("Sync client dial failed: %v", err) return } defer sc.close() var sid SyncSessionID self := sc.engine.config.Node.IPv4Addr // Register for synchronisation events. // TODO(jsing): Implement timeout on RPC? if err := sc.client.Call("SeesawSync.Register", self, &sid); err != nil { log.Warningf("Sync registration failed: %v", err) return } log.Infof("Registered for synchronisation notifications (ID %d)", sid) // TODO(jsing): Export synchronisation data to ECU/CLI. sc.poll(sid) // Attempt to deregister for notifications. // TODO(jsing): Implement timeout on RPC? if err := sc.client.Call("SeesawSync.Deregister", sid, nil); err != nil { log.Warningf("Sync deregistration failed: %v", err) } }
[ "func", "(", "sc", "*", "syncClient", ")", "runOnce", "(", ")", "{", "if", "err", ":=", "sc", ".", "dial", "(", ")", ";", "err", "!=", "nil", "{", "log", ".", "Warningf", "(", "\"Sync client dial failed: %v\"", ",", "err", ")", "\n", "return", "\n", "}", "\n", "defer", "sc", ".", "close", "(", ")", "\n", "var", "sid", "SyncSessionID", "\n", "self", ":=", "sc", ".", "engine", ".", "config", ".", "Node", ".", "IPv4Addr", "\n", "if", "err", ":=", "sc", ".", "client", ".", "Call", "(", "\"SeesawSync.Register\"", ",", "self", ",", "&", "sid", ")", ";", "err", "!=", "nil", "{", "log", ".", "Warningf", "(", "\"Sync registration failed: %v\"", ",", "err", ")", "\n", "return", "\n", "}", "\n", "log", ".", "Infof", "(", "\"Registered for synchronisation notifications (ID %d)\"", ",", "sid", ")", "\n", "sc", ".", "poll", "(", "sid", ")", "\n", "if", "err", ":=", "sc", ".", "client", ".", "Call", "(", "\"SeesawSync.Deregister\"", ",", "sid", ",", "nil", ")", ";", "err", "!=", "nil", "{", "log", ".", "Warningf", "(", "\"Sync deregistration failed: %v\"", ",", "err", ")", "\n", "}", "\n", "}" ]
// runOnce establishes a connection to the synchronisation server, registers // for notifications, polls for notifications, then deregisters.
[ "runOnce", "establishes", "a", "connection", "to", "the", "synchronisation", "server", "registers", "for", "notifications", "polls", "for", "notifications", "then", "deregisters", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/sync.go#L425-L452
train
google/seesaw
engine/sync.go
poll
func (sc *syncClient) poll(sid SyncSessionID) { for { var sn SyncNotes poll := sc.client.Go("SeesawSync.Poll", sid, &sn, nil) select { case <-poll.Done: if poll.Error != nil { log.Errorf("Synchronisation polling failed: %v", poll.Error) return } for _, note := range sn.Notes { sc.dispatch(&note) } case <-sc.quit: sc.stopped <- true return case <-time.After(syncPollTimeout): log.Warningf("Synchronisation polling timed out after %s", syncPollTimeout) return } } }
go
func (sc *syncClient) poll(sid SyncSessionID) { for { var sn SyncNotes poll := sc.client.Go("SeesawSync.Poll", sid, &sn, nil) select { case <-poll.Done: if poll.Error != nil { log.Errorf("Synchronisation polling failed: %v", poll.Error) return } for _, note := range sn.Notes { sc.dispatch(&note) } case <-sc.quit: sc.stopped <- true return case <-time.After(syncPollTimeout): log.Warningf("Synchronisation polling timed out after %s", syncPollTimeout) return } } }
[ "func", "(", "sc", "*", "syncClient", ")", "poll", "(", "sid", "SyncSessionID", ")", "{", "for", "{", "var", "sn", "SyncNotes", "\n", "poll", ":=", "sc", ".", "client", ".", "Go", "(", "\"SeesawSync.Poll\"", ",", "sid", ",", "&", "sn", ",", "nil", ")", "\n", "select", "{", "case", "<-", "poll", ".", "Done", ":", "if", "poll", ".", "Error", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"Synchronisation polling failed: %v\"", ",", "poll", ".", "Error", ")", "\n", "return", "\n", "}", "\n", "for", "_", ",", "note", ":=", "range", "sn", ".", "Notes", "{", "sc", ".", "dispatch", "(", "&", "note", ")", "\n", "}", "\n", "case", "<-", "sc", ".", "quit", ":", "sc", ".", "stopped", "<-", "true", "\n", "return", "\n", "case", "<-", "time", ".", "After", "(", "syncPollTimeout", ")", ":", "log", ".", "Warningf", "(", "\"Synchronisation polling timed out after %s\"", ",", "syncPollTimeout", ")", "\n", "return", "\n", "}", "\n", "}", "\n", "}" ]
// poll polls the synchronisation server for notifications, then dispatches // them for processing.
[ "poll", "polls", "the", "synchronisation", "server", "for", "notifications", "then", "dispatches", "them", "for", "processing", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/sync.go#L456-L479
train
google/seesaw
engine/sync.go
handleNote
func (sc *syncClient) handleNote(note *SyncNote) { switch note.Type { case SNTHeartbeat: log.V(1).Infoln("Sync client received heartbeat") case SNTDesync: sc.handleDesync() case SNTConfigUpdate: sc.handleConfigUpdate(note) case SNTHealthcheck: sc.handleHealthcheck(note) case SNTOverride: sc.handleOverride(note) default: log.Errorf("Unable to handle sync notification type %s (%d)", note.Type, note.Type) } }
go
func (sc *syncClient) handleNote(note *SyncNote) { switch note.Type { case SNTHeartbeat: log.V(1).Infoln("Sync client received heartbeat") case SNTDesync: sc.handleDesync() case SNTConfigUpdate: sc.handleConfigUpdate(note) case SNTHealthcheck: sc.handleHealthcheck(note) case SNTOverride: sc.handleOverride(note) default: log.Errorf("Unable to handle sync notification type %s (%d)", note.Type, note.Type) } }
[ "func", "(", "sc", "*", "syncClient", ")", "handleNote", "(", "note", "*", "SyncNote", ")", "{", "switch", "note", ".", "Type", "{", "case", "SNTHeartbeat", ":", "log", ".", "V", "(", "1", ")", ".", "Infoln", "(", "\"Sync client received heartbeat\"", ")", "\n", "case", "SNTDesync", ":", "sc", ".", "handleDesync", "(", ")", "\n", "case", "SNTConfigUpdate", ":", "sc", ".", "handleConfigUpdate", "(", "note", ")", "\n", "case", "SNTHealthcheck", ":", "sc", ".", "handleHealthcheck", "(", "note", ")", "\n", "case", "SNTOverride", ":", "sc", ".", "handleOverride", "(", "note", ")", "\n", "default", ":", "log", ".", "Errorf", "(", "\"Unable to handle sync notification type %s (%d)\"", ",", "note", ".", "Type", ",", "note", ".", "Type", ")", "\n", "}", "\n", "}" ]
// handleNote dispatches a synchronisation note to the appropriate handler.
[ "handleNote", "dispatches", "a", "synchronisation", "note", "to", "the", "appropriate", "handler", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/sync.go#L482-L502
train
google/seesaw
engine/sync.go
handleOverride
func (sc *syncClient) handleOverride(sn *SyncNote) { log.V(1).Infoln("Sync client received override notification") if o := sn.VserverOverride; o != nil { sc.engine.queueOverride(o) } if o := sn.DestinationOverride; o != nil { sc.engine.queueOverride(o) } if o := sn.BackendOverride; o != nil { sc.engine.queueOverride(o) } }
go
func (sc *syncClient) handleOverride(sn *SyncNote) { log.V(1).Infoln("Sync client received override notification") if o := sn.VserverOverride; o != nil { sc.engine.queueOverride(o) } if o := sn.DestinationOverride; o != nil { sc.engine.queueOverride(o) } if o := sn.BackendOverride; o != nil { sc.engine.queueOverride(o) } }
[ "func", "(", "sc", "*", "syncClient", ")", "handleOverride", "(", "sn", "*", "SyncNote", ")", "{", "log", ".", "V", "(", "1", ")", ".", "Infoln", "(", "\"Sync client received override notification\"", ")", "\n", "if", "o", ":=", "sn", ".", "VserverOverride", ";", "o", "!=", "nil", "{", "sc", ".", "engine", ".", "queueOverride", "(", "o", ")", "\n", "}", "\n", "if", "o", ":=", "sn", ".", "DestinationOverride", ";", "o", "!=", "nil", "{", "sc", ".", "engine", ".", "queueOverride", "(", "o", ")", "\n", "}", "\n", "if", "o", ":=", "sn", ".", "BackendOverride", ";", "o", "!=", "nil", "{", "sc", ".", "engine", ".", "queueOverride", "(", "o", ")", "\n", "}", "\n", "}" ]
// handleOverride handles an override notification.
[ "handleOverride", "handles", "an", "override", "notification", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/sync.go#L523-L535
train
google/seesaw
engine/sync.go
run
func (sc *syncClient) run() error { for { select { case <-sc.stopped: <-sc.start log.Infof("Starting sync client...") default: sc.runOnce() select { case <-time.After(5 * time.Second): case <-sc.quit: sc.stopped <- true } } } }
go
func (sc *syncClient) run() error { for { select { case <-sc.stopped: <-sc.start log.Infof("Starting sync client...") default: sc.runOnce() select { case <-time.After(5 * time.Second): case <-sc.quit: sc.stopped <- true } } } }
[ "func", "(", "sc", "*", "syncClient", ")", "run", "(", ")", "error", "{", "for", "{", "select", "{", "case", "<-", "sc", ".", "stopped", ":", "<-", "sc", ".", "start", "\n", "log", ".", "Infof", "(", "\"Starting sync client...\"", ")", "\n", "default", ":", "sc", ".", "runOnce", "(", ")", "\n", "select", "{", "case", "<-", "time", ".", "After", "(", "5", "*", "time", ".", "Second", ")", ":", "case", "<-", "sc", ".", "quit", ":", "sc", ".", "stopped", "<-", "true", "\n", "}", "\n", "}", "\n", "}", "\n", "}" ]
// run runs the synchronisation client.
[ "run", "runs", "the", "synchronisation", "client", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/sync.go#L538-L553
train
google/seesaw
engine/sync.go
enable
func (sc *syncClient) enable() { sc.lock.Lock() start := !sc.enabled sc.enabled = true sc.lock.Unlock() if start { sc.start <- true } }
go
func (sc *syncClient) enable() { sc.lock.Lock() start := !sc.enabled sc.enabled = true sc.lock.Unlock() if start { sc.start <- true } }
[ "func", "(", "sc", "*", "syncClient", ")", "enable", "(", ")", "{", "sc", ".", "lock", ".", "Lock", "(", ")", "\n", "start", ":=", "!", "sc", ".", "enabled", "\n", "sc", ".", "enabled", "=", "true", "\n", "sc", ".", "lock", ".", "Unlock", "(", ")", "\n", "if", "start", "{", "sc", ".", "start", "<-", "true", "\n", "}", "\n", "}" ]
// enable enables synchronisation with our peer Seesaw node.
[ "enable", "enables", "synchronisation", "with", "our", "peer", "Seesaw", "node", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/sync.go#L556-L564
train
google/seesaw
engine/sync.go
disable
func (sc *syncClient) disable() { sc.lock.Lock() quit := sc.enabled sc.enabled = false sc.lock.Unlock() if quit { sc.quit <- true } }
go
func (sc *syncClient) disable() { sc.lock.Lock() quit := sc.enabled sc.enabled = false sc.lock.Unlock() if quit { sc.quit <- true } }
[ "func", "(", "sc", "*", "syncClient", ")", "disable", "(", ")", "{", "sc", ".", "lock", ".", "Lock", "(", ")", "\n", "quit", ":=", "sc", ".", "enabled", "\n", "sc", ".", "enabled", "=", "false", "\n", "sc", ".", "lock", ".", "Unlock", "(", ")", "\n", "if", "quit", "{", "sc", ".", "quit", "<-", "true", "\n", "}", "\n", "}" ]
// disable disables synchronisation with our peer Seesaw node.
[ "disable", "disables", "synchronisation", "with", "our", "peer", "Seesaw", "node", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/sync.go#L567-L575
train
google/seesaw
common/seesaw/seesaw.go
String
func (sc Component) String() string { if name, ok := componentNames[sc]; ok { return name } return "(unknown)" }
go
func (sc Component) String() string { if name, ok := componentNames[sc]; ok { return name } return "(unknown)" }
[ "func", "(", "sc", "Component", ")", "String", "(", ")", "string", "{", "if", "name", ",", "ok", ":=", "componentNames", "[", "sc", "]", ";", "ok", "{", "return", "name", "\n", "}", "\n", "return", "\"(unknown)\"", "\n", "}" ]
// String returns the string representation of a Component.
[ "String", "returns", "the", "string", "representation", "of", "a", "Component", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/seesaw.go#L93-L98
train
google/seesaw
common/seesaw/seesaw.go
String
func (h HealthcheckType) String() string { switch h { case HCTypeDNS: return "DNS" case HCTypeHTTP: return "HTTP" // TODO(angusc): Drop HTTPS as a separate type. case HCTypeHTTPS: return "HTTP" // NB: Not HTTPS case HCTypeICMP: return "ICMP" case HCTypeRADIUS: return "RADIUS" case HCTypeTCP: return "TCP" // TODO(angusc): Drop TCPTLS as a separate type. case HCTypeTCPTLS: return "TCP" // NB: Not TCPTLS case HCTypeUDP: return "UDP" } return "(unknown)" }
go
func (h HealthcheckType) String() string { switch h { case HCTypeDNS: return "DNS" case HCTypeHTTP: return "HTTP" // TODO(angusc): Drop HTTPS as a separate type. case HCTypeHTTPS: return "HTTP" // NB: Not HTTPS case HCTypeICMP: return "ICMP" case HCTypeRADIUS: return "RADIUS" case HCTypeTCP: return "TCP" // TODO(angusc): Drop TCPTLS as a separate type. case HCTypeTCPTLS: return "TCP" // NB: Not TCPTLS case HCTypeUDP: return "UDP" } return "(unknown)" }
[ "func", "(", "h", "HealthcheckType", ")", "String", "(", ")", "string", "{", "switch", "h", "{", "case", "HCTypeDNS", ":", "return", "\"DNS\"", "\n", "case", "HCTypeHTTP", ":", "return", "\"HTTP\"", "\n", "case", "HCTypeHTTPS", ":", "return", "\"HTTP\"", "\n", "case", "HCTypeICMP", ":", "return", "\"ICMP\"", "\n", "case", "HCTypeRADIUS", ":", "return", "\"RADIUS\"", "\n", "case", "HCTypeTCP", ":", "return", "\"TCP\"", "\n", "case", "HCTypeTCPTLS", ":", "return", "\"TCP\"", "\n", "case", "HCTypeUDP", ":", "return", "\"UDP\"", "\n", "}", "\n", "return", "\"(unknown)\"", "\n", "}" ]
// String returns the name for the given HealthcheckType.
[ "String", "returns", "the", "name", "for", "the", "given", "HealthcheckType", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/seesaw.go#L159-L181
train
google/seesaw
common/seesaw/seesaw.go
String
func (v VIP) String() string { return fmt.Sprintf("%v (%v)", v.IP, v.Type) }
go
func (v VIP) String() string { return fmt.Sprintf("%v (%v)", v.IP, v.Type) }
[ "func", "(", "v", "VIP", ")", "String", "(", ")", "string", "{", "return", "fmt", ".", "Sprintf", "(", "\"%v (%v)\"", ",", "v", ".", "IP", ",", "v", ".", "Type", ")", "\n", "}" ]
// String returns the string representation of a VIP.
[ "String", "returns", "the", "string", "representation", "of", "a", "VIP", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/seesaw.go#L213-L215
train
google/seesaw
common/seesaw/seesaw.go
NewVIP
func NewVIP(ip net.IP, vipSubnets map[string]*net.IPNet) *VIP { vipType := UnicastVIP switch { case IsAnycast(ip): vipType = AnycastVIP case InSubnets(ip, vipSubnets): vipType = DedicatedVIP } return &VIP{ IP: NewIP(ip), Type: vipType, } }
go
func NewVIP(ip net.IP, vipSubnets map[string]*net.IPNet) *VIP { vipType := UnicastVIP switch { case IsAnycast(ip): vipType = AnycastVIP case InSubnets(ip, vipSubnets): vipType = DedicatedVIP } return &VIP{ IP: NewIP(ip), Type: vipType, } }
[ "func", "NewVIP", "(", "ip", "net", ".", "IP", ",", "vipSubnets", "map", "[", "string", "]", "*", "net", ".", "IPNet", ")", "*", "VIP", "{", "vipType", ":=", "UnicastVIP", "\n", "switch", "{", "case", "IsAnycast", "(", "ip", ")", ":", "vipType", "=", "AnycastVIP", "\n", "case", "InSubnets", "(", "ip", ",", "vipSubnets", ")", ":", "vipType", "=", "DedicatedVIP", "\n", "}", "\n", "return", "&", "VIP", "{", "IP", ":", "NewIP", "(", "ip", ")", ",", "Type", ":", "vipType", ",", "}", "\n", "}" ]
// NewVIP returns a seesaw VIP.
[ "NewVIP", "returns", "a", "seesaw", "VIP", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/seesaw.go#L218-L230
train
google/seesaw
common/seesaw/seesaw.go
NewIP
func NewIP(nip net.IP) IP { var ip IP copy(ip[:], nip.To16()) return ip }
go
func NewIP(nip net.IP) IP { var ip IP copy(ip[:], nip.To16()) return ip }
[ "func", "NewIP", "(", "nip", "net", ".", "IP", ")", "IP", "{", "var", "ip", "IP", "\n", "copy", "(", "ip", "[", ":", "]", ",", "nip", ".", "To16", "(", ")", ")", "\n", "return", "ip", "\n", "}" ]
// NewIP returns a seesaw IP initialised from a net.IP address.
[ "NewIP", "returns", "a", "seesaw", "IP", "initialised", "from", "a", "net", ".", "IP", "address", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/seesaw.go#L236-L240
train
google/seesaw
common/seesaw/seesaw.go
AF
func (ip IP) AF() AF { if ip.IP().To4() != nil { return IPv4 } return IPv6 }
go
func (ip IP) AF() AF { if ip.IP().To4() != nil { return IPv4 } return IPv6 }
[ "func", "(", "ip", "IP", ")", "AF", "(", ")", "AF", "{", "if", "ip", ".", "IP", "(", ")", ".", "To4", "(", ")", "!=", "nil", "{", "return", "IPv4", "\n", "}", "\n", "return", "IPv6", "\n", "}" ]
// AF returns the address family of a seesaw IP address.
[ "AF", "returns", "the", "address", "family", "of", "a", "seesaw", "IP", "address", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/seesaw.go#L260-L265
train
google/seesaw
common/seesaw/seesaw.go
String
func (lbm LBMode) String() string { if name, ok := modeNames[lbm]; ok { return name } return "(unknown)" }
go
func (lbm LBMode) String() string { if name, ok := modeNames[lbm]; ok { return name } return "(unknown)" }
[ "func", "(", "lbm", "LBMode", ")", "String", "(", ")", "string", "{", "if", "name", ",", "ok", ":=", "modeNames", "[", "lbm", "]", ";", "ok", "{", "return", "name", "\n", "}", "\n", "return", "\"(unknown)\"", "\n", "}" ]
// String returns the string representation of a LBMode.
[ "String", "returns", "the", "string", "representation", "of", "a", "LBMode", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/seesaw.go#L313-L318
train
google/seesaw
common/seesaw/seesaw.go
String
func (lbs LBScheduler) String() string { if name, ok := schedulerNames[lbs]; ok { return name } return "(unknown)" }
go
func (lbs LBScheduler) String() string { if name, ok := schedulerNames[lbs]; ok { return name } return "(unknown)" }
[ "func", "(", "lbs", "LBScheduler", ")", "String", "(", ")", "string", "{", "if", "name", ",", "ok", ":=", "schedulerNames", "[", "lbs", "]", ";", "ok", "{", "return", "name", "\n", "}", "\n", "return", "\"(unknown)\"", "\n", "}" ]
// String returns the string representation of a LBScheduler.
[ "String", "returns", "the", "string", "representation", "of", "a", "LBScheduler", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/seesaw.go#L342-L347
train
google/seesaw
healthcheck/dial.go
setSocketMark
func setSocketMark(fd, mark int) error { if err := syscall.SetsockoptInt(fd, syscall.SOL_SOCKET, syscall.SO_MARK, mark); err != nil { return os.NewSyscallError("failed to set mark", err) } return nil }
go
func setSocketMark(fd, mark int) error { if err := syscall.SetsockoptInt(fd, syscall.SOL_SOCKET, syscall.SO_MARK, mark); err != nil { return os.NewSyscallError("failed to set mark", err) } return nil }
[ "func", "setSocketMark", "(", "fd", ",", "mark", "int", ")", "error", "{", "if", "err", ":=", "syscall", ".", "SetsockoptInt", "(", "fd", ",", "syscall", ".", "SOL_SOCKET", ",", "syscall", ".", "SO_MARK", ",", "mark", ")", ";", "err", "!=", "nil", "{", "return", "os", ".", "NewSyscallError", "(", "\"failed to set mark\"", ",", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// setSocketMark sets packet marking on the given socket.
[ "setSocketMark", "sets", "packet", "marking", "on", "the", "given", "socket", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/dial.go#L198-L203
train
google/seesaw
healthcheck/dial.go
setSocketTimeout
func setSocketTimeout(fd int, timeout time.Duration) error { tv := syscall.NsecToTimeval(timeout.Nanoseconds()) for _, opt := range []int{syscall.SO_RCVTIMEO, syscall.SO_SNDTIMEO} { if err := syscall.SetsockoptTimeval(fd, syscall.SOL_SOCKET, opt, &tv); err != nil { return os.NewSyscallError("setsockopt", err) } } return nil }
go
func setSocketTimeout(fd int, timeout time.Duration) error { tv := syscall.NsecToTimeval(timeout.Nanoseconds()) for _, opt := range []int{syscall.SO_RCVTIMEO, syscall.SO_SNDTIMEO} { if err := syscall.SetsockoptTimeval(fd, syscall.SOL_SOCKET, opt, &tv); err != nil { return os.NewSyscallError("setsockopt", err) } } return nil }
[ "func", "setSocketTimeout", "(", "fd", "int", ",", "timeout", "time", ".", "Duration", ")", "error", "{", "tv", ":=", "syscall", ".", "NsecToTimeval", "(", "timeout", ".", "Nanoseconds", "(", ")", ")", "\n", "for", "_", ",", "opt", ":=", "range", "[", "]", "int", "{", "syscall", ".", "SO_RCVTIMEO", ",", "syscall", ".", "SO_SNDTIMEO", "}", "{", "if", "err", ":=", "syscall", ".", "SetsockoptTimeval", "(", "fd", ",", "syscall", ".", "SOL_SOCKET", ",", "opt", ",", "&", "tv", ")", ";", "err", "!=", "nil", "{", "return", "os", ".", "NewSyscallError", "(", "\"setsockopt\"", ",", "err", ")", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// setSocketTimeout sets the receive and send timeouts on the given socket.
[ "setSocketTimeout", "sets", "the", "receive", "and", "send", "timeouts", "on", "the", "given", "socket", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/dial.go#L206-L214
train
google/seesaw
engine/vserver.go
newVserver
func newVserver(e *Engine) *vserver { return &vserver{ engine: e, ncc: ncclient.NewNCC(e.config.NCCSocket), fwm: make(map[seesaw.AF]uint32), active: make(map[seesaw.IP]bool), lbVservers: make(map[seesaw.IP]*seesaw.Vserver), vips: make(map[seesaw.VIP]bool), overrideChan: make(chan seesaw.Override, 5), notify: make(chan *checkNotification, 20), update: make(chan *config.Vserver, 1), quit: make(chan bool, 1), stopped: make(chan bool, 1), } }
go
func newVserver(e *Engine) *vserver { return &vserver{ engine: e, ncc: ncclient.NewNCC(e.config.NCCSocket), fwm: make(map[seesaw.AF]uint32), active: make(map[seesaw.IP]bool), lbVservers: make(map[seesaw.IP]*seesaw.Vserver), vips: make(map[seesaw.VIP]bool), overrideChan: make(chan seesaw.Override, 5), notify: make(chan *checkNotification, 20), update: make(chan *config.Vserver, 1), quit: make(chan bool, 1), stopped: make(chan bool, 1), } }
[ "func", "newVserver", "(", "e", "*", "Engine", ")", "*", "vserver", "{", "return", "&", "vserver", "{", "engine", ":", "e", ",", "ncc", ":", "ncclient", ".", "NewNCC", "(", "e", ".", "config", ".", "NCCSocket", ")", ",", "fwm", ":", "make", "(", "map", "[", "seesaw", ".", "AF", "]", "uint32", ")", ",", "active", ":", "make", "(", "map", "[", "seesaw", ".", "IP", "]", "bool", ")", ",", "lbVservers", ":", "make", "(", "map", "[", "seesaw", ".", "IP", "]", "*", "seesaw", ".", "Vserver", ")", ",", "vips", ":", "make", "(", "map", "[", "seesaw", ".", "VIP", "]", "bool", ")", ",", "overrideChan", ":", "make", "(", "chan", "seesaw", ".", "Override", ",", "5", ")", ",", "notify", ":", "make", "(", "chan", "*", "checkNotification", ",", "20", ")", ",", "update", ":", "make", "(", "chan", "*", "config", ".", "Vserver", ",", "1", ")", ",", "quit", ":", "make", "(", "chan", "bool", ",", "1", ")", ",", "stopped", ":", "make", "(", "chan", "bool", ",", "1", ")", ",", "}", "\n", "}" ]
// newVserver returns an initialised vserver struct.
[ "newVserver", "returns", "an", "initialised", "vserver", "struct", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/vserver.go#L61-L78
train
google/seesaw
engine/vserver.go
String
func (v *vserver) String() string { if v.config != nil { return v.config.Name } return fmt.Sprintf("Unconfigured vserver %+v", *v) }
go
func (v *vserver) String() string { if v.config != nil { return v.config.Name } return fmt.Sprintf("Unconfigured vserver %+v", *v) }
[ "func", "(", "v", "*", "vserver", ")", "String", "(", ")", "string", "{", "if", "v", ".", "config", "!=", "nil", "{", "return", "v", ".", "config", ".", "Name", "\n", "}", "\n", "return", "fmt", ".", "Sprintf", "(", "\"Unconfigured vserver %+v\"", ",", "*", "v", ")", "\n", "}" ]
// String returns a string representing a vserver.
[ "String", "returns", "a", "string", "representing", "a", "vserver", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/vserver.go#L81-L86
train
google/seesaw
engine/vserver.go
ipvsService
func (svc *service) ipvsService() *ipvs.Service { var flags ipvs.ServiceFlags if svc.ventry.Persistence > 0 { flags |= ipvs.SFPersistent } if svc.ventry.OnePacket { flags |= ipvs.SFOnePacket } var ip net.IP switch { case svc.fwm > 0 && svc.af == seesaw.IPv4: ip = net.IPv4zero case svc.fwm > 0 && svc.af == seesaw.IPv6: ip = net.IPv6zero default: ip = svc.ip.IP() } return &ipvs.Service{ Address: ip, Protocol: ipvs.IPProto(svc.proto), Port: svc.port, Scheduler: svc.ventry.Scheduler.String(), FirewallMark: svc.fwm, Flags: flags, Timeout: uint32(svc.ventry.Persistence), } }
go
func (svc *service) ipvsService() *ipvs.Service { var flags ipvs.ServiceFlags if svc.ventry.Persistence > 0 { flags |= ipvs.SFPersistent } if svc.ventry.OnePacket { flags |= ipvs.SFOnePacket } var ip net.IP switch { case svc.fwm > 0 && svc.af == seesaw.IPv4: ip = net.IPv4zero case svc.fwm > 0 && svc.af == seesaw.IPv6: ip = net.IPv6zero default: ip = svc.ip.IP() } return &ipvs.Service{ Address: ip, Protocol: ipvs.IPProto(svc.proto), Port: svc.port, Scheduler: svc.ventry.Scheduler.String(), FirewallMark: svc.fwm, Flags: flags, Timeout: uint32(svc.ventry.Persistence), } }
[ "func", "(", "svc", "*", "service", ")", "ipvsService", "(", ")", "*", "ipvs", ".", "Service", "{", "var", "flags", "ipvs", ".", "ServiceFlags", "\n", "if", "svc", ".", "ventry", ".", "Persistence", ">", "0", "{", "flags", "|=", "ipvs", ".", "SFPersistent", "\n", "}", "\n", "if", "svc", ".", "ventry", ".", "OnePacket", "{", "flags", "|=", "ipvs", ".", "SFOnePacket", "\n", "}", "\n", "var", "ip", "net", ".", "IP", "\n", "switch", "{", "case", "svc", ".", "fwm", ">", "0", "&&", "svc", ".", "af", "==", "seesaw", ".", "IPv4", ":", "ip", "=", "net", ".", "IPv4zero", "\n", "case", "svc", ".", "fwm", ">", "0", "&&", "svc", ".", "af", "==", "seesaw", ".", "IPv6", ":", "ip", "=", "net", ".", "IPv6zero", "\n", "default", ":", "ip", "=", "svc", ".", "ip", ".", "IP", "(", ")", "\n", "}", "\n", "return", "&", "ipvs", ".", "Service", "{", "Address", ":", "ip", ",", "Protocol", ":", "ipvs", ".", "IPProto", "(", "svc", ".", "proto", ")", ",", "Port", ":", "svc", ".", "port", ",", "Scheduler", ":", "svc", ".", "ventry", ".", "Scheduler", ".", "String", "(", ")", ",", "FirewallMark", ":", "svc", ".", "fwm", ",", "Flags", ":", "flags", ",", "Timeout", ":", "uint32", "(", "svc", ".", "ventry", ".", "Persistence", ")", ",", "}", "\n", "}" ]
// ipvsService returns an IPVS Service for the given service.
[ "ipvsService", "returns", "an", "IPVS", "Service", "for", "the", "given", "service", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/vserver.go#L110-L136
train
google/seesaw
engine/vserver.go
ipvsEqual
func (s *service) ipvsEqual(other *service) bool { return s.ipvsSvc.Equal(*other.ipvsSvc) && s.ventry.Mode == other.ventry.Mode && s.ventry.LThreshold == other.ventry.LThreshold && s.ventry.UThreshold == other.ventry.UThreshold }
go
func (s *service) ipvsEqual(other *service) bool { return s.ipvsSvc.Equal(*other.ipvsSvc) && s.ventry.Mode == other.ventry.Mode && s.ventry.LThreshold == other.ventry.LThreshold && s.ventry.UThreshold == other.ventry.UThreshold }
[ "func", "(", "s", "*", "service", ")", "ipvsEqual", "(", "other", "*", "service", ")", "bool", "{", "return", "s", ".", "ipvsSvc", ".", "Equal", "(", "*", "other", ".", "ipvsSvc", ")", "&&", "s", ".", "ventry", ".", "Mode", "==", "other", ".", "ventry", ".", "Mode", "&&", "s", ".", "ventry", ".", "LThreshold", "==", "other", ".", "ventry", ".", "LThreshold", "&&", "s", ".", "ventry", ".", "UThreshold", "==", "other", ".", "ventry", ".", "UThreshold", "\n", "}" ]
// ipvsEqual returns true if two services have the same IPVS configuration. // Transient state and the services' destinations are ignored.
[ "ipvsEqual", "returns", "true", "if", "two", "services", "have", "the", "same", "IPVS", "configuration", ".", "Transient", "state", "and", "the", "services", "destinations", "are", "ignored", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/vserver.go#L140-L145
train
google/seesaw
engine/vserver.go
String
func (s *service) String() string { if s.fwm != 0 { return fmt.Sprintf("%v/fwm:%d", s.ip, s.fwm) } ip := s.ip.String() port := strconv.Itoa(int(s.port)) return fmt.Sprintf("%v/%v", net.JoinHostPort(ip, port), s.proto) }
go
func (s *service) String() string { if s.fwm != 0 { return fmt.Sprintf("%v/fwm:%d", s.ip, s.fwm) } ip := s.ip.String() port := strconv.Itoa(int(s.port)) return fmt.Sprintf("%v/%v", net.JoinHostPort(ip, port), s.proto) }
[ "func", "(", "s", "*", "service", ")", "String", "(", ")", "string", "{", "if", "s", ".", "fwm", "!=", "0", "{", "return", "fmt", ".", "Sprintf", "(", "\"%v/fwm:%d\"", ",", "s", ".", "ip", ",", "s", ".", "fwm", ")", "\n", "}", "\n", "ip", ":=", "s", ".", "ip", ".", "String", "(", ")", "\n", "port", ":=", "strconv", ".", "Itoa", "(", "int", "(", "s", ".", "port", ")", ")", "\n", "return", "fmt", ".", "Sprintf", "(", "\"%v/%v\"", ",", "net", ".", "JoinHostPort", "(", "ip", ",", "port", ")", ",", "s", ".", "proto", ")", "\n", "}" ]
// String returns a string representing a service.
[ "String", "returns", "a", "string", "representing", "a", "service", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/vserver.go#L148-L155
train
google/seesaw
engine/vserver.go
ipvsDestination
func (dst *destination) ipvsDestination() *ipvs.Destination { var flags ipvs.DestinationFlags switch dst.service.ventry.Mode { case seesaw.LBModeNone: log.Warningf("%v: Unspecified LB mode", dst) case seesaw.LBModeDSR: flags |= ipvs.DFForwardRoute case seesaw.LBModeNAT: flags |= ipvs.DFForwardMasq } return &ipvs.Destination{ Address: dst.ip.IP(), Port: dst.service.port, Weight: dst.weight, Flags: flags, LowerThreshold: uint32(dst.service.ventry.LThreshold), UpperThreshold: uint32(dst.service.ventry.UThreshold), } }
go
func (dst *destination) ipvsDestination() *ipvs.Destination { var flags ipvs.DestinationFlags switch dst.service.ventry.Mode { case seesaw.LBModeNone: log.Warningf("%v: Unspecified LB mode", dst) case seesaw.LBModeDSR: flags |= ipvs.DFForwardRoute case seesaw.LBModeNAT: flags |= ipvs.DFForwardMasq } return &ipvs.Destination{ Address: dst.ip.IP(), Port: dst.service.port, Weight: dst.weight, Flags: flags, LowerThreshold: uint32(dst.service.ventry.LThreshold), UpperThreshold: uint32(dst.service.ventry.UThreshold), } }
[ "func", "(", "dst", "*", "destination", ")", "ipvsDestination", "(", ")", "*", "ipvs", ".", "Destination", "{", "var", "flags", "ipvs", ".", "DestinationFlags", "\n", "switch", "dst", ".", "service", ".", "ventry", ".", "Mode", "{", "case", "seesaw", ".", "LBModeNone", ":", "log", ".", "Warningf", "(", "\"%v: Unspecified LB mode\"", ",", "dst", ")", "\n", "case", "seesaw", ".", "LBModeDSR", ":", "flags", "|=", "ipvs", ".", "DFForwardRoute", "\n", "case", "seesaw", ".", "LBModeNAT", ":", "flags", "|=", "ipvs", ".", "DFForwardMasq", "\n", "}", "\n", "return", "&", "ipvs", ".", "Destination", "{", "Address", ":", "dst", ".", "ip", ".", "IP", "(", ")", ",", "Port", ":", "dst", ".", "service", ".", "port", ",", "Weight", ":", "dst", ".", "weight", ",", "Flags", ":", "flags", ",", "LowerThreshold", ":", "uint32", "(", "dst", ".", "service", ".", "ventry", ".", "LThreshold", ")", ",", "UpperThreshold", ":", "uint32", "(", "dst", ".", "service", ".", "ventry", ".", "UThreshold", ")", ",", "}", "\n", "}" ]
// ipvsDestination returns an IPVS Destination for the given destination.
[ "ipvsDestination", "returns", "an", "IPVS", "Destination", "for", "the", "given", "destination", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/vserver.go#L181-L199
train
google/seesaw
engine/vserver.go
ipvsEqual
func (d *destination) ipvsEqual(other *destination) bool { return d.ipvsDst.Equal(*other.ipvsDst) }
go
func (d *destination) ipvsEqual(other *destination) bool { return d.ipvsDst.Equal(*other.ipvsDst) }
[ "func", "(", "d", "*", "destination", ")", "ipvsEqual", "(", "other", "*", "destination", ")", "bool", "{", "return", "d", ".", "ipvsDst", ".", "Equal", "(", "*", "other", ".", "ipvsDst", ")", "\n", "}" ]
// ipvsEqual returns true if two destinations have the same IPVS configuration. // Transient state is ignored.
[ "ipvsEqual", "returns", "true", "if", "two", "destinations", "have", "the", "same", "IPVS", "configuration", ".", "Transient", "state", "is", "ignored", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/vserver.go#L203-L205
train
google/seesaw
engine/vserver.go
String
func (d *destination) String() string { if d.service.fwm != 0 { return fmt.Sprintf("%v", d.ip) } ip := d.ip.String() port := strconv.Itoa(int(d.service.port)) return fmt.Sprintf("%v/%v", net.JoinHostPort(ip, port), d.service.proto) }
go
func (d *destination) String() string { if d.service.fwm != 0 { return fmt.Sprintf("%v", d.ip) } ip := d.ip.String() port := strconv.Itoa(int(d.service.port)) return fmt.Sprintf("%v/%v", net.JoinHostPort(ip, port), d.service.proto) }
[ "func", "(", "d", "*", "destination", ")", "String", "(", ")", "string", "{", "if", "d", ".", "service", ".", "fwm", "!=", "0", "{", "return", "fmt", ".", "Sprintf", "(", "\"%v\"", ",", "d", ".", "ip", ")", "\n", "}", "\n", "ip", ":=", "d", ".", "ip", ".", "String", "(", ")", "\n", "port", ":=", "strconv", ".", "Itoa", "(", "int", "(", "d", ".", "service", ".", "port", ")", ")", "\n", "return", "fmt", ".", "Sprintf", "(", "\"%v/%v\"", ",", "net", ".", "JoinHostPort", "(", "ip", ",", "port", ")", ",", "d", ".", "service", ".", "proto", ")", "\n", "}" ]
// String returns a string representing a destination.
[ "String", "returns", "a", "string", "representing", "a", "destination", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/vserver.go#L208-L215
train
google/seesaw
engine/vserver.go
name
func (d *destination) name() string { return fmt.Sprintf("%v/%v", d.service.vserver.String(), d.String()) }
go
func (d *destination) name() string { return fmt.Sprintf("%v/%v", d.service.vserver.String(), d.String()) }
[ "func", "(", "d", "*", "destination", ")", "name", "(", ")", "string", "{", "return", "fmt", ".", "Sprintf", "(", "\"%v/%v\"", ",", "d", ".", "service", ".", "vserver", ".", "String", "(", ")", ",", "d", ".", "String", "(", ")", ")", "\n", "}" ]
// name returns the name of a destination.
[ "name", "returns", "the", "name", "of", "a", "destination", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/vserver.go#L218-L220
train
google/seesaw
engine/vserver.go
newCheckKey
func newCheckKey(vip, bip seesaw.IP, port uint16, proto seesaw.IPProto, h *config.Healthcheck) checkKey { return checkKey{ vserverIP: vip, backendIP: bip, servicePort: port, serviceProtocol: proto, healthcheckMode: h.Mode, healthcheckType: h.Type, healthcheckPort: h.Port, name: h.Name, } }
go
func newCheckKey(vip, bip seesaw.IP, port uint16, proto seesaw.IPProto, h *config.Healthcheck) checkKey { return checkKey{ vserverIP: vip, backendIP: bip, servicePort: port, serviceProtocol: proto, healthcheckMode: h.Mode, healthcheckType: h.Type, healthcheckPort: h.Port, name: h.Name, } }
[ "func", "newCheckKey", "(", "vip", ",", "bip", "seesaw", ".", "IP", ",", "port", "uint16", ",", "proto", "seesaw", ".", "IPProto", ",", "h", "*", "config", ".", "Healthcheck", ")", "checkKey", "{", "return", "checkKey", "{", "vserverIP", ":", "vip", ",", "backendIP", ":", "bip", ",", "servicePort", ":", "port", ",", "serviceProtocol", ":", "proto", ",", "healthcheckMode", ":", "h", ".", "Mode", ",", "healthcheckType", ":", "h", ".", "Type", ",", "healthcheckPort", ":", "h", ".", "Port", ",", "name", ":", "h", ".", "Name", ",", "}", "\n", "}" ]
// newCheckKey returns an initialised checkKey.
[ "newCheckKey", "returns", "an", "initialised", "checkKey", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/vserver.go#L235-L246
train
google/seesaw
engine/vserver.go
String
func (c checkKey) String() string { return fmt.Sprintf("%v:%d/%v backend %v:%d/%v %v %v port %d (%s)", c.vserverIP, c.servicePort, c.serviceProtocol, c.backendIP, c.servicePort, c.serviceProtocol, c.healthcheckMode, c.healthcheckType, c.healthcheckPort, c.name) }
go
func (c checkKey) String() string { return fmt.Sprintf("%v:%d/%v backend %v:%d/%v %v %v port %d (%s)", c.vserverIP, c.servicePort, c.serviceProtocol, c.backendIP, c.servicePort, c.serviceProtocol, c.healthcheckMode, c.healthcheckType, c.healthcheckPort, c.name) }
[ "func", "(", "c", "checkKey", ")", "String", "(", ")", "string", "{", "return", "fmt", ".", "Sprintf", "(", "\"%v:%d/%v backend %v:%d/%v %v %v port %d (%s)\"", ",", "c", ".", "vserverIP", ",", "c", ".", "servicePort", ",", "c", ".", "serviceProtocol", ",", "c", ".", "backendIP", ",", "c", ".", "servicePort", ",", "c", ".", "serviceProtocol", ",", "c", ".", "healthcheckMode", ",", "c", ".", "healthcheckType", ",", "c", ".", "healthcheckPort", ",", "c", ".", "name", ")", "\n", "}" ]
// String returns the string representation of a checkKey.
[ "String", "returns", "the", "string", "representation", "of", "a", "checkKey", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/vserver.go#L249-L254
train
google/seesaw
engine/vserver.go
newCheck
func newCheck(key checkKey, v *vserver, h *config.Healthcheck) *check { return &check{ key: key, vserver: v, healthcheck: h, } }
go
func newCheck(key checkKey, v *vserver, h *config.Healthcheck) *check { return &check{ key: key, vserver: v, healthcheck: h, } }
[ "func", "newCheck", "(", "key", "checkKey", ",", "v", "*", "vserver", ",", "h", "*", "config", ".", "Healthcheck", ")", "*", "check", "{", "return", "&", "check", "{", "key", ":", "key", ",", "vserver", ":", "v", ",", "healthcheck", ":", "h", ",", "}", "\n", "}" ]
// newCheck returns an initialised check.
[ "newCheck", "returns", "an", "initialised", "check", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/vserver.go#L267-L273
train
google/seesaw
engine/vserver.go
expandServices
func (v *vserver) expandServices() map[serviceKey]*service { if v.config.UseFWM { return v.expandFWMServices() } svcs := make(map[serviceKey]*service) for _, af := range seesaw.AFs() { var ip net.IP switch af { case seesaw.IPv4: ip = v.config.Host.IPv4Addr case seesaw.IPv6: ip = v.config.Host.IPv6Addr } if ip == nil { continue } for _, entry := range v.config.Entries { svc := &service{ serviceKey: serviceKey{ af: af, proto: entry.Proto, port: entry.Port, }, ip: seesaw.NewIP(ip), ventry: entry, vserver: v, dests: make(map[destinationKey]*destination, 0), stats: &seesaw.ServiceStats{}, } svc.ipvsSvc = svc.ipvsService() svcs[svc.serviceKey] = svc } } return svcs }
go
func (v *vserver) expandServices() map[serviceKey]*service { if v.config.UseFWM { return v.expandFWMServices() } svcs := make(map[serviceKey]*service) for _, af := range seesaw.AFs() { var ip net.IP switch af { case seesaw.IPv4: ip = v.config.Host.IPv4Addr case seesaw.IPv6: ip = v.config.Host.IPv6Addr } if ip == nil { continue } for _, entry := range v.config.Entries { svc := &service{ serviceKey: serviceKey{ af: af, proto: entry.Proto, port: entry.Port, }, ip: seesaw.NewIP(ip), ventry: entry, vserver: v, dests: make(map[destinationKey]*destination, 0), stats: &seesaw.ServiceStats{}, } svc.ipvsSvc = svc.ipvsService() svcs[svc.serviceKey] = svc } } return svcs }
[ "func", "(", "v", "*", "vserver", ")", "expandServices", "(", ")", "map", "[", "serviceKey", "]", "*", "service", "{", "if", "v", ".", "config", ".", "UseFWM", "{", "return", "v", ".", "expandFWMServices", "(", ")", "\n", "}", "\n", "svcs", ":=", "make", "(", "map", "[", "serviceKey", "]", "*", "service", ")", "\n", "for", "_", ",", "af", ":=", "range", "seesaw", ".", "AFs", "(", ")", "{", "var", "ip", "net", ".", "IP", "\n", "switch", "af", "{", "case", "seesaw", ".", "IPv4", ":", "ip", "=", "v", ".", "config", ".", "Host", ".", "IPv4Addr", "\n", "case", "seesaw", ".", "IPv6", ":", "ip", "=", "v", ".", "config", ".", "Host", ".", "IPv6Addr", "\n", "}", "\n", "if", "ip", "==", "nil", "{", "continue", "\n", "}", "\n", "for", "_", ",", "entry", ":=", "range", "v", ".", "config", ".", "Entries", "{", "svc", ":=", "&", "service", "{", "serviceKey", ":", "serviceKey", "{", "af", ":", "af", ",", "proto", ":", "entry", ".", "Proto", ",", "port", ":", "entry", ".", "Port", ",", "}", ",", "ip", ":", "seesaw", ".", "NewIP", "(", "ip", ")", ",", "ventry", ":", "entry", ",", "vserver", ":", "v", ",", "dests", ":", "make", "(", "map", "[", "destinationKey", "]", "*", "destination", ",", "0", ")", ",", "stats", ":", "&", "seesaw", ".", "ServiceStats", "{", "}", ",", "}", "\n", "svc", ".", "ipvsSvc", "=", "svc", ".", "ipvsService", "(", ")", "\n", "svcs", "[", "svc", ".", "serviceKey", "]", "=", "svc", "\n", "}", "\n", "}", "\n", "return", "svcs", "\n", "}" ]
// expandServices returns a list of services that have been expanded from the // vserver configuration.
[ "expandServices", "returns", "a", "list", "of", "services", "that", "have", "been", "expanded", "from", "the", "vserver", "configuration", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/vserver.go#L290-L325
train
google/seesaw
engine/vserver.go
expandFWMServices
func (v *vserver) expandFWMServices() map[serviceKey]*service { svcs := make(map[serviceKey]*service) for _, af := range seesaw.AFs() { var ip net.IP switch af { case seesaw.IPv4: ip = v.config.Host.IPv4Addr case seesaw.IPv6: ip = v.config.Host.IPv6Addr } if ip == nil { continue } // Persistence, etc., is stored in the VserverEntry. For FWM services, these // values must be the same for all VserverEntries, so just use the first // one. var ventry *config.VserverEntry for _, entry := range v.config.Entries { ventry = entry break } if v.fwm[af] == 0 { mark, err := v.engine.fwmAlloc.get() if err != nil { log.Fatalf("%v: failed to get mark: %v", v, err) } v.fwm[af] = mark } svc := &service{ serviceKey: serviceKey{ af: af, fwm: v.fwm[af], }, ip: seesaw.NewIP(ip), ventry: ventry, vserver: v, stats: &seesaw.ServiceStats{}, } svc.ipvsSvc = svc.ipvsService() svcs[svc.serviceKey] = svc } return svcs }
go
func (v *vserver) expandFWMServices() map[serviceKey]*service { svcs := make(map[serviceKey]*service) for _, af := range seesaw.AFs() { var ip net.IP switch af { case seesaw.IPv4: ip = v.config.Host.IPv4Addr case seesaw.IPv6: ip = v.config.Host.IPv6Addr } if ip == nil { continue } // Persistence, etc., is stored in the VserverEntry. For FWM services, these // values must be the same for all VserverEntries, so just use the first // one. var ventry *config.VserverEntry for _, entry := range v.config.Entries { ventry = entry break } if v.fwm[af] == 0 { mark, err := v.engine.fwmAlloc.get() if err != nil { log.Fatalf("%v: failed to get mark: %v", v, err) } v.fwm[af] = mark } svc := &service{ serviceKey: serviceKey{ af: af, fwm: v.fwm[af], }, ip: seesaw.NewIP(ip), ventry: ventry, vserver: v, stats: &seesaw.ServiceStats{}, } svc.ipvsSvc = svc.ipvsService() svcs[svc.serviceKey] = svc } return svcs }
[ "func", "(", "v", "*", "vserver", ")", "expandFWMServices", "(", ")", "map", "[", "serviceKey", "]", "*", "service", "{", "svcs", ":=", "make", "(", "map", "[", "serviceKey", "]", "*", "service", ")", "\n", "for", "_", ",", "af", ":=", "range", "seesaw", ".", "AFs", "(", ")", "{", "var", "ip", "net", ".", "IP", "\n", "switch", "af", "{", "case", "seesaw", ".", "IPv4", ":", "ip", "=", "v", ".", "config", ".", "Host", ".", "IPv4Addr", "\n", "case", "seesaw", ".", "IPv6", ":", "ip", "=", "v", ".", "config", ".", "Host", ".", "IPv6Addr", "\n", "}", "\n", "if", "ip", "==", "nil", "{", "continue", "\n", "}", "\n", "var", "ventry", "*", "config", ".", "VserverEntry", "\n", "for", "_", ",", "entry", ":=", "range", "v", ".", "config", ".", "Entries", "{", "ventry", "=", "entry", "\n", "break", "\n", "}", "\n", "if", "v", ".", "fwm", "[", "af", "]", "==", "0", "{", "mark", ",", "err", ":=", "v", ".", "engine", ".", "fwmAlloc", ".", "get", "(", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Fatalf", "(", "\"%v: failed to get mark: %v\"", ",", "v", ",", "err", ")", "\n", "}", "\n", "v", ".", "fwm", "[", "af", "]", "=", "mark", "\n", "}", "\n", "svc", ":=", "&", "service", "{", "serviceKey", ":", "serviceKey", "{", "af", ":", "af", ",", "fwm", ":", "v", ".", "fwm", "[", "af", "]", ",", "}", ",", "ip", ":", "seesaw", ".", "NewIP", "(", "ip", ")", ",", "ventry", ":", "ventry", ",", "vserver", ":", "v", ",", "stats", ":", "&", "seesaw", ".", "ServiceStats", "{", "}", ",", "}", "\n", "svc", ".", "ipvsSvc", "=", "svc", ".", "ipvsService", "(", ")", "\n", "svcs", "[", "svc", ".", "serviceKey", "]", "=", "svc", "\n", "}", "\n", "return", "svcs", "\n", "}" ]
// expandFWMServices returns a list of services that have been expanded from the // vserver configuration for a firewall mark based vserver.
[ "expandFWMServices", "returns", "a", "list", "of", "services", "that", "have", "been", "expanded", "from", "the", "vserver", "configuration", "for", "a", "firewall", "mark", "based", "vserver", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/vserver.go#L329-L373
train
google/seesaw
engine/vserver.go
expandDests
func (v *vserver) expandDests(svc *service) map[destinationKey]*destination { dsts := make(map[destinationKey]*destination, len(v.config.Backends)) for _, backend := range v.config.Backends { var ip net.IP switch svc.af { case seesaw.IPv4: ip = backend.Host.IPv4Addr case seesaw.IPv6: ip = backend.Host.IPv6Addr } if ip == nil { continue } dst := &destination{ destinationKey: newDestinationKey(ip), service: svc, backend: backend, weight: backend.Weight, } dst.ipvsDst = dst.ipvsDestination() dst.stats = &seesaw.DestinationStats{} dsts[dst.destinationKey] = dst } return dsts }
go
func (v *vserver) expandDests(svc *service) map[destinationKey]*destination { dsts := make(map[destinationKey]*destination, len(v.config.Backends)) for _, backend := range v.config.Backends { var ip net.IP switch svc.af { case seesaw.IPv4: ip = backend.Host.IPv4Addr case seesaw.IPv6: ip = backend.Host.IPv6Addr } if ip == nil { continue } dst := &destination{ destinationKey: newDestinationKey(ip), service: svc, backend: backend, weight: backend.Weight, } dst.ipvsDst = dst.ipvsDestination() dst.stats = &seesaw.DestinationStats{} dsts[dst.destinationKey] = dst } return dsts }
[ "func", "(", "v", "*", "vserver", ")", "expandDests", "(", "svc", "*", "service", ")", "map", "[", "destinationKey", "]", "*", "destination", "{", "dsts", ":=", "make", "(", "map", "[", "destinationKey", "]", "*", "destination", ",", "len", "(", "v", ".", "config", ".", "Backends", ")", ")", "\n", "for", "_", ",", "backend", ":=", "range", "v", ".", "config", ".", "Backends", "{", "var", "ip", "net", ".", "IP", "\n", "switch", "svc", ".", "af", "{", "case", "seesaw", ".", "IPv4", ":", "ip", "=", "backend", ".", "Host", ".", "IPv4Addr", "\n", "case", "seesaw", ".", "IPv6", ":", "ip", "=", "backend", ".", "Host", ".", "IPv6Addr", "\n", "}", "\n", "if", "ip", "==", "nil", "{", "continue", "\n", "}", "\n", "dst", ":=", "&", "destination", "{", "destinationKey", ":", "newDestinationKey", "(", "ip", ")", ",", "service", ":", "svc", ",", "backend", ":", "backend", ",", "weight", ":", "backend", ".", "Weight", ",", "}", "\n", "dst", ".", "ipvsDst", "=", "dst", ".", "ipvsDestination", "(", ")", "\n", "dst", ".", "stats", "=", "&", "seesaw", ".", "DestinationStats", "{", "}", "\n", "dsts", "[", "dst", ".", "destinationKey", "]", "=", "dst", "\n", "}", "\n", "return", "dsts", "\n", "}" ]
// expandDests returns a list of destinations that have been expanded from the // vserver configuration and a given service.
[ "expandDests", "returns", "a", "list", "of", "destinations", "that", "have", "been", "expanded", "from", "the", "vserver", "configuration", "and", "a", "given", "service", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/vserver.go#L377-L401
train
google/seesaw
engine/vserver.go
expandChecks
func (v *vserver) expandChecks() map[checkKey]*check { checks := make(map[checkKey]*check) for _, svc := range v.services { for _, dest := range svc.dests { dest.checks = make([]*check, 0) if !dest.backend.Enabled { continue } for _, hc := range v.config.Healthchecks { // vserver-level healthchecks key := newCheckKey(svc.ip, dest.ip, 0, 0, hc) c := checks[key] if c == nil { c = newCheck(key, v, hc) checks[key] = c } dest.checks = append(dest.checks, c) c.dests = append(c.dests, dest) } // ventry-level healthchecks if v.config.UseFWM { for _, ve := range svc.vserver.config.Entries { for _, hc := range ve.Healthchecks { key := newCheckKey(svc.ip, dest.ip, ve.Port, ve.Proto, hc) c := newCheck(key, v, hc) checks[key] = c dest.checks = append(dest.checks, c) c.dests = append(c.dests, dest) } } } else { for _, hc := range svc.ventry.Healthchecks { key := newCheckKey(svc.ip, dest.ip, svc.port, svc.proto, hc) c := newCheck(key, v, hc) checks[key] = c dest.checks = append(dest.checks, c) c.dests = append(c.dests, dest) } } } } return checks }
go
func (v *vserver) expandChecks() map[checkKey]*check { checks := make(map[checkKey]*check) for _, svc := range v.services { for _, dest := range svc.dests { dest.checks = make([]*check, 0) if !dest.backend.Enabled { continue } for _, hc := range v.config.Healthchecks { // vserver-level healthchecks key := newCheckKey(svc.ip, dest.ip, 0, 0, hc) c := checks[key] if c == nil { c = newCheck(key, v, hc) checks[key] = c } dest.checks = append(dest.checks, c) c.dests = append(c.dests, dest) } // ventry-level healthchecks if v.config.UseFWM { for _, ve := range svc.vserver.config.Entries { for _, hc := range ve.Healthchecks { key := newCheckKey(svc.ip, dest.ip, ve.Port, ve.Proto, hc) c := newCheck(key, v, hc) checks[key] = c dest.checks = append(dest.checks, c) c.dests = append(c.dests, dest) } } } else { for _, hc := range svc.ventry.Healthchecks { key := newCheckKey(svc.ip, dest.ip, svc.port, svc.proto, hc) c := newCheck(key, v, hc) checks[key] = c dest.checks = append(dest.checks, c) c.dests = append(c.dests, dest) } } } } return checks }
[ "func", "(", "v", "*", "vserver", ")", "expandChecks", "(", ")", "map", "[", "checkKey", "]", "*", "check", "{", "checks", ":=", "make", "(", "map", "[", "checkKey", "]", "*", "check", ")", "\n", "for", "_", ",", "svc", ":=", "range", "v", ".", "services", "{", "for", "_", ",", "dest", ":=", "range", "svc", ".", "dests", "{", "dest", ".", "checks", "=", "make", "(", "[", "]", "*", "check", ",", "0", ")", "\n", "if", "!", "dest", ".", "backend", ".", "Enabled", "{", "continue", "\n", "}", "\n", "for", "_", ",", "hc", ":=", "range", "v", ".", "config", ".", "Healthchecks", "{", "key", ":=", "newCheckKey", "(", "svc", ".", "ip", ",", "dest", ".", "ip", ",", "0", ",", "0", ",", "hc", ")", "\n", "c", ":=", "checks", "[", "key", "]", "\n", "if", "c", "==", "nil", "{", "c", "=", "newCheck", "(", "key", ",", "v", ",", "hc", ")", "\n", "checks", "[", "key", "]", "=", "c", "\n", "}", "\n", "dest", ".", "checks", "=", "append", "(", "dest", ".", "checks", ",", "c", ")", "\n", "c", ".", "dests", "=", "append", "(", "c", ".", "dests", ",", "dest", ")", "\n", "}", "\n", "if", "v", ".", "config", ".", "UseFWM", "{", "for", "_", ",", "ve", ":=", "range", "svc", ".", "vserver", ".", "config", ".", "Entries", "{", "for", "_", ",", "hc", ":=", "range", "ve", ".", "Healthchecks", "{", "key", ":=", "newCheckKey", "(", "svc", ".", "ip", ",", "dest", ".", "ip", ",", "ve", ".", "Port", ",", "ve", ".", "Proto", ",", "hc", ")", "\n", "c", ":=", "newCheck", "(", "key", ",", "v", ",", "hc", ")", "\n", "checks", "[", "key", "]", "=", "c", "\n", "dest", ".", "checks", "=", "append", "(", "dest", ".", "checks", ",", "c", ")", "\n", "c", ".", "dests", "=", "append", "(", "c", ".", "dests", ",", "dest", ")", "\n", "}", "\n", "}", "\n", "}", "else", "{", "for", "_", ",", "hc", ":=", "range", "svc", ".", "ventry", ".", "Healthchecks", "{", "key", ":=", "newCheckKey", "(", "svc", ".", "ip", ",", "dest", ".", "ip", ",", "svc", ".", "port", ",", "svc", ".", "proto", ",", "hc", ")", "\n", "c", ":=", "newCheck", "(", "key", ",", "v", ",", "hc", ")", "\n", "checks", "[", "key", "]", "=", "c", "\n", "dest", ".", "checks", "=", "append", "(", "dest", ".", "checks", ",", "c", ")", "\n", "c", ".", "dests", "=", "append", "(", "c", ".", "dests", ",", "dest", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "checks", "\n", "}" ]
// expandChecks returns a list of checks that have been expanded from the // vserver configuration.
[ "expandChecks", "returns", "a", "list", "of", "checks", "that", "have", "been", "expanded", "from", "the", "vserver", "configuration", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/vserver.go#L405-L448
train
google/seesaw
engine/vserver.go
healthchecks
func (v *vserver) healthchecks() vserverChecks { vc := vserverChecks{vserverName: v.config.Name} if v.enabled { vc.checks = v.checks } return vc }
go
func (v *vserver) healthchecks() vserverChecks { vc := vserverChecks{vserverName: v.config.Name} if v.enabled { vc.checks = v.checks } return vc }
[ "func", "(", "v", "*", "vserver", ")", "healthchecks", "(", ")", "vserverChecks", "{", "vc", ":=", "vserverChecks", "{", "vserverName", ":", "v", ".", "config", ".", "Name", "}", "\n", "if", "v", ".", "enabled", "{", "vc", ".", "checks", "=", "v", ".", "checks", "\n", "}", "\n", "return", "vc", "\n", "}" ]
// healthchecks returns the vserverChecks for a vserver.
[ "healthchecks", "returns", "the", "vserverChecks", "for", "a", "vserver", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/vserver.go#L451-L457
train
google/seesaw
engine/vserver.go
run
func (v *vserver) run() { statsTicker := time.NewTicker(v.engine.config.StatsInterval) for { select { case <-v.quit: // Shutdown active vservers, services and destinations. // There is no race between this and new healthcheck // notifications, since they are also handled via the // same vserver go routine. v.downAll() statsTicker.Stop() v.engine.hcManager.vcc <- vserverChecks{vserverName: v.config.Name} v.unconfigureVIPs() // Return any firewall marks that were allocated to // this vserver. for _, fwm := range v.fwm { v.engine.fwmAlloc.put(fwm) } v.stopped <- true return case o := <-v.overrideChan: v.handleOverride(o) v.engine.hcManager.vcc <- v.healthchecks() case config := <-v.update: v.handleConfigUpdate(config) v.engine.hcManager.vcc <- v.healthchecks() case n := <-v.notify: v.handleCheckNotification(n) case <-statsTicker.C: v.updateStats() } // Something changed - export a new vserver snapshot. // The goroutine that drains v.engine.vserverChan also does a blocking write // to each vserver's vserver.notify channel, which is drained by each // vserver's goroutine (i.e., this one). So we need a timeout to avoid a // deadlock. timeout := time.After(1 * time.Second) select { case v.engine.vserverChan <- v.snapshot(): case <-timeout: log.Warningf("%v: failed to send snapshot", v) } } }
go
func (v *vserver) run() { statsTicker := time.NewTicker(v.engine.config.StatsInterval) for { select { case <-v.quit: // Shutdown active vservers, services and destinations. // There is no race between this and new healthcheck // notifications, since they are also handled via the // same vserver go routine. v.downAll() statsTicker.Stop() v.engine.hcManager.vcc <- vserverChecks{vserverName: v.config.Name} v.unconfigureVIPs() // Return any firewall marks that were allocated to // this vserver. for _, fwm := range v.fwm { v.engine.fwmAlloc.put(fwm) } v.stopped <- true return case o := <-v.overrideChan: v.handleOverride(o) v.engine.hcManager.vcc <- v.healthchecks() case config := <-v.update: v.handleConfigUpdate(config) v.engine.hcManager.vcc <- v.healthchecks() case n := <-v.notify: v.handleCheckNotification(n) case <-statsTicker.C: v.updateStats() } // Something changed - export a new vserver snapshot. // The goroutine that drains v.engine.vserverChan also does a blocking write // to each vserver's vserver.notify channel, which is drained by each // vserver's goroutine (i.e., this one). So we need a timeout to avoid a // deadlock. timeout := time.After(1 * time.Second) select { case v.engine.vserverChan <- v.snapshot(): case <-timeout: log.Warningf("%v: failed to send snapshot", v) } } }
[ "func", "(", "v", "*", "vserver", ")", "run", "(", ")", "{", "statsTicker", ":=", "time", ".", "NewTicker", "(", "v", ".", "engine", ".", "config", ".", "StatsInterval", ")", "\n", "for", "{", "select", "{", "case", "<-", "v", ".", "quit", ":", "v", ".", "downAll", "(", ")", "\n", "statsTicker", ".", "Stop", "(", ")", "\n", "v", ".", "engine", ".", "hcManager", ".", "vcc", "<-", "vserverChecks", "{", "vserverName", ":", "v", ".", "config", ".", "Name", "}", "\n", "v", ".", "unconfigureVIPs", "(", ")", "\n", "for", "_", ",", "fwm", ":=", "range", "v", ".", "fwm", "{", "v", ".", "engine", ".", "fwmAlloc", ".", "put", "(", "fwm", ")", "\n", "}", "\n", "v", ".", "stopped", "<-", "true", "\n", "return", "\n", "case", "o", ":=", "<-", "v", ".", "overrideChan", ":", "v", ".", "handleOverride", "(", "o", ")", "\n", "v", ".", "engine", ".", "hcManager", ".", "vcc", "<-", "v", ".", "healthchecks", "(", ")", "\n", "case", "config", ":=", "<-", "v", ".", "update", ":", "v", ".", "handleConfigUpdate", "(", "config", ")", "\n", "v", ".", "engine", ".", "hcManager", ".", "vcc", "<-", "v", ".", "healthchecks", "(", ")", "\n", "case", "n", ":=", "<-", "v", ".", "notify", ":", "v", ".", "handleCheckNotification", "(", "n", ")", "\n", "case", "<-", "statsTicker", ".", "C", ":", "v", ".", "updateStats", "(", ")", "\n", "}", "\n", "timeout", ":=", "time", ".", "After", "(", "1", "*", "time", ".", "Second", ")", "\n", "select", "{", "case", "v", ".", "engine", ".", "vserverChan", "<-", "v", ".", "snapshot", "(", ")", ":", "case", "<-", "timeout", ":", "log", ".", "Warningf", "(", "\"%v: failed to send snapshot\"", ",", "v", ")", "\n", "}", "\n", "}", "\n", "}" ]
// run invokes a vserver. This is a long-lived Go routine that lasts for the // duration of the vserver, reacting to configuration changes and healthcheck // notifications.
[ "run", "invokes", "a", "vserver", ".", "This", "is", "a", "long", "-", "lived", "Go", "routine", "that", "lasts", "for", "the", "duration", "of", "the", "vserver", "reacting", "to", "configuration", "changes", "and", "healthcheck", "notifications", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/vserver.go#L462-L512
train
google/seesaw
engine/vserver.go
handleConfigUpdate
func (v *vserver) handleConfigUpdate(config *config.Vserver) { if config == nil { return } switch { case v.config == nil: v.configInit(config) return case v.enabled && !vserverEnabled(config, v.vserverOverride.State()): log.Infof("%v: disabling vserver", v) v.downAll() v.unconfigureVIPs() v.configInit(config) return case !v.enabled && !vserverEnabled(config, v.vserverOverride.State()): v.configInit(config) return case !v.enabled && vserverEnabled(config, v.vserverOverride.State()): log.Infof("%v: enabling vserver", v) v.configInit(config) return default: // Some updates require changes to the iptables rules. Since we currently // can't make fine-grained changes to the iptables rules, we must // re-initialise the entire vserver. This is necessary in the following // scenarios: // - A port or protocol is added, removed or changed // - A vserver is changed from FWM to non-FWM or vice versa // - A vserverEntry is changed from DSR to NAT or vice versa // // (Changing a VIP address also requires updating iptables, but // v.configUpdate() handles this case) // // TODO(angusc): Add support for finer-grained updates to ncc so we can // avoid re-initialising the vserver in these cases. reInit := false switch { case config.UseFWM != v.config.UseFWM: reInit = true case len(config.Entries) != len(v.config.Entries): reInit = true default: for k, entry := range config.Entries { if v.config.Entries[k] == nil { reInit = true break } if v.config.Entries[k].Mode != entry.Mode { reInit = true break } } } if reInit { log.Infof("%v: re-initialising vserver", v) v.downAll() v.unconfigureVIPs() v.configInit(config) return } v.config = config v.configUpdate() } }
go
func (v *vserver) handleConfigUpdate(config *config.Vserver) { if config == nil { return } switch { case v.config == nil: v.configInit(config) return case v.enabled && !vserverEnabled(config, v.vserverOverride.State()): log.Infof("%v: disabling vserver", v) v.downAll() v.unconfigureVIPs() v.configInit(config) return case !v.enabled && !vserverEnabled(config, v.vserverOverride.State()): v.configInit(config) return case !v.enabled && vserverEnabled(config, v.vserverOverride.State()): log.Infof("%v: enabling vserver", v) v.configInit(config) return default: // Some updates require changes to the iptables rules. Since we currently // can't make fine-grained changes to the iptables rules, we must // re-initialise the entire vserver. This is necessary in the following // scenarios: // - A port or protocol is added, removed or changed // - A vserver is changed from FWM to non-FWM or vice versa // - A vserverEntry is changed from DSR to NAT or vice versa // // (Changing a VIP address also requires updating iptables, but // v.configUpdate() handles this case) // // TODO(angusc): Add support for finer-grained updates to ncc so we can // avoid re-initialising the vserver in these cases. reInit := false switch { case config.UseFWM != v.config.UseFWM: reInit = true case len(config.Entries) != len(v.config.Entries): reInit = true default: for k, entry := range config.Entries { if v.config.Entries[k] == nil { reInit = true break } if v.config.Entries[k].Mode != entry.Mode { reInit = true break } } } if reInit { log.Infof("%v: re-initialising vserver", v) v.downAll() v.unconfigureVIPs() v.configInit(config) return } v.config = config v.configUpdate() } }
[ "func", "(", "v", "*", "vserver", ")", "handleConfigUpdate", "(", "config", "*", "config", ".", "Vserver", ")", "{", "if", "config", "==", "nil", "{", "return", "\n", "}", "\n", "switch", "{", "case", "v", ".", "config", "==", "nil", ":", "v", ".", "configInit", "(", "config", ")", "\n", "return", "\n", "case", "v", ".", "enabled", "&&", "!", "vserverEnabled", "(", "config", ",", "v", ".", "vserverOverride", ".", "State", "(", ")", ")", ":", "log", ".", "Infof", "(", "\"%v: disabling vserver\"", ",", "v", ")", "\n", "v", ".", "downAll", "(", ")", "\n", "v", ".", "unconfigureVIPs", "(", ")", "\n", "v", ".", "configInit", "(", "config", ")", "\n", "return", "\n", "case", "!", "v", ".", "enabled", "&&", "!", "vserverEnabled", "(", "config", ",", "v", ".", "vserverOverride", ".", "State", "(", ")", ")", ":", "v", ".", "configInit", "(", "config", ")", "\n", "return", "\n", "case", "!", "v", ".", "enabled", "&&", "vserverEnabled", "(", "config", ",", "v", ".", "vserverOverride", ".", "State", "(", ")", ")", ":", "log", ".", "Infof", "(", "\"%v: enabling vserver\"", ",", "v", ")", "\n", "v", ".", "configInit", "(", "config", ")", "\n", "return", "\n", "default", ":", "reInit", ":=", "false", "\n", "switch", "{", "case", "config", ".", "UseFWM", "!=", "v", ".", "config", ".", "UseFWM", ":", "reInit", "=", "true", "\n", "case", "len", "(", "config", ".", "Entries", ")", "!=", "len", "(", "v", ".", "config", ".", "Entries", ")", ":", "reInit", "=", "true", "\n", "default", ":", "for", "k", ",", "entry", ":=", "range", "config", ".", "Entries", "{", "if", "v", ".", "config", ".", "Entries", "[", "k", "]", "==", "nil", "{", "reInit", "=", "true", "\n", "break", "\n", "}", "\n", "if", "v", ".", "config", ".", "Entries", "[", "k", "]", ".", "Mode", "!=", "entry", ".", "Mode", "{", "reInit", "=", "true", "\n", "break", "\n", "}", "\n", "}", "\n", "}", "\n", "if", "reInit", "{", "log", ".", "Infof", "(", "\"%v: re-initialising vserver\"", ",", "v", ")", "\n", "v", ".", "downAll", "(", ")", "\n", "v", ".", "unconfigureVIPs", "(", ")", "\n", "v", ".", "configInit", "(", "config", ")", "\n", "return", "\n", "}", "\n", "v", ".", "config", "=", "config", "\n", "v", ".", "configUpdate", "(", ")", "\n", "}", "\n", "}" ]
// handleConfigUpdate updates the internal structures of a vserver using the // new configuration.
[ "handleConfigUpdate", "updates", "the", "internal", "structures", "of", "a", "vserver", "using", "the", "new", "configuration", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/vserver.go#L543-L611
train
google/seesaw
engine/vserver.go
configInit
func (v *vserver) configInit(config *config.Vserver) { v.config = config v.enabled = vserverEnabled(config, v.vserverOverride.State()) newSvcs := v.expandServices() // Preserve stats if this is a reinit for svcK, svc := range newSvcs { svc.dests = v.expandDests(svc) if oldSvc, ok := v.services[svcK]; ok { *svc.stats = *oldSvc.stats for dstK, dst := range svc.dests { if oldDst, ok := oldSvc.dests[dstK]; ok { *dst.stats = *oldDst.stats } } } } v.services = newSvcs v.checks = v.expandChecks() if v.enabled { v.configureVIPs() } return }
go
func (v *vserver) configInit(config *config.Vserver) { v.config = config v.enabled = vserverEnabled(config, v.vserverOverride.State()) newSvcs := v.expandServices() // Preserve stats if this is a reinit for svcK, svc := range newSvcs { svc.dests = v.expandDests(svc) if oldSvc, ok := v.services[svcK]; ok { *svc.stats = *oldSvc.stats for dstK, dst := range svc.dests { if oldDst, ok := oldSvc.dests[dstK]; ok { *dst.stats = *oldDst.stats } } } } v.services = newSvcs v.checks = v.expandChecks() if v.enabled { v.configureVIPs() } return }
[ "func", "(", "v", "*", "vserver", ")", "configInit", "(", "config", "*", "config", ".", "Vserver", ")", "{", "v", ".", "config", "=", "config", "\n", "v", ".", "enabled", "=", "vserverEnabled", "(", "config", ",", "v", ".", "vserverOverride", ".", "State", "(", ")", ")", "\n", "newSvcs", ":=", "v", ".", "expandServices", "(", ")", "\n", "for", "svcK", ",", "svc", ":=", "range", "newSvcs", "{", "svc", ".", "dests", "=", "v", ".", "expandDests", "(", "svc", ")", "\n", "if", "oldSvc", ",", "ok", ":=", "v", ".", "services", "[", "svcK", "]", ";", "ok", "{", "*", "svc", ".", "stats", "=", "*", "oldSvc", ".", "stats", "\n", "for", "dstK", ",", "dst", ":=", "range", "svc", ".", "dests", "{", "if", "oldDst", ",", "ok", ":=", "oldSvc", ".", "dests", "[", "dstK", "]", ";", "ok", "{", "*", "dst", ".", "stats", "=", "*", "oldDst", ".", "stats", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n", "v", ".", "services", "=", "newSvcs", "\n", "v", ".", "checks", "=", "v", ".", "expandChecks", "(", ")", "\n", "if", "v", ".", "enabled", "{", "v", ".", "configureVIPs", "(", ")", "\n", "}", "\n", "return", "\n", "}" ]
// configInit initialises all services, destinations, healthchecks and VIPs for // a vserver.
[ "configInit", "initialises", "all", "services", "destinations", "healthchecks", "and", "VIPs", "for", "a", "vserver", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/vserver.go#L615-L637
train
google/seesaw
engine/vserver.go
configUpdate
func (v *vserver) configUpdate() { newSvcs := v.expandServices() for svcKey, newSvc := range newSvcs { if svc, ok := v.services[svcKey]; ok { if svc.ip.Equal(newSvc.ip) { svc.update(newSvc) continue } log.Infof("%v: service %v: new IP address: %v", v, svc, newSvc.ip) v.deleteService(svc) } log.Infof("%v: adding new service: %v", v, newSvc) v.services[svcKey] = newSvc v.updateState(newSvc.ip) } for svcKey, svc := range v.services { if newSvcs[svcKey] == nil { // Service no longer exists v.deleteService(svc) continue } // Update destinations for this service newDests := v.expandDests(svc) for destKey, newDest := range newDests { if dest, ok := svc.dests[destKey]; ok { dest.update(newDest) continue } log.Infof("%v: service %v: adding new destination: %v", v, svc, newDest) svc.dests[destKey] = newDest } for destKey, dest := range svc.dests { if newDests[destKey] == nil { // Destination no longer exists if dest.active { dest.healthy = false svc.updateState() } log.Infof("%v: service %v: deleting destination: %v", v, svc, dest) delete(svc.dests, destKey) } } } // If a VIP has been re-IP'd or has no services configured, remove the old // VIP from the interface. needVIPs := make(map[seesaw.IP]bool) for _, svc := range v.services { needVIPs[svc.ip] = true } for vip := range v.vips { if !needVIPs[vip.IP] { log.Infof("%v: unconfiguring no longer needed VIP %v", v, vip.IP) v.unconfigureVIP(&vip) } } checks := v.expandChecks() for k, oldCheck := range v.checks { if checks[k] != nil { checks[k].description = oldCheck.description checks[k].status = oldCheck.status } } v.checks = checks // TODO(baptr): Should this only happen if it's enabled? v.configureVIPs() return }
go
func (v *vserver) configUpdate() { newSvcs := v.expandServices() for svcKey, newSvc := range newSvcs { if svc, ok := v.services[svcKey]; ok { if svc.ip.Equal(newSvc.ip) { svc.update(newSvc) continue } log.Infof("%v: service %v: new IP address: %v", v, svc, newSvc.ip) v.deleteService(svc) } log.Infof("%v: adding new service: %v", v, newSvc) v.services[svcKey] = newSvc v.updateState(newSvc.ip) } for svcKey, svc := range v.services { if newSvcs[svcKey] == nil { // Service no longer exists v.deleteService(svc) continue } // Update destinations for this service newDests := v.expandDests(svc) for destKey, newDest := range newDests { if dest, ok := svc.dests[destKey]; ok { dest.update(newDest) continue } log.Infof("%v: service %v: adding new destination: %v", v, svc, newDest) svc.dests[destKey] = newDest } for destKey, dest := range svc.dests { if newDests[destKey] == nil { // Destination no longer exists if dest.active { dest.healthy = false svc.updateState() } log.Infof("%v: service %v: deleting destination: %v", v, svc, dest) delete(svc.dests, destKey) } } } // If a VIP has been re-IP'd or has no services configured, remove the old // VIP from the interface. needVIPs := make(map[seesaw.IP]bool) for _, svc := range v.services { needVIPs[svc.ip] = true } for vip := range v.vips { if !needVIPs[vip.IP] { log.Infof("%v: unconfiguring no longer needed VIP %v", v, vip.IP) v.unconfigureVIP(&vip) } } checks := v.expandChecks() for k, oldCheck := range v.checks { if checks[k] != nil { checks[k].description = oldCheck.description checks[k].status = oldCheck.status } } v.checks = checks // TODO(baptr): Should this only happen if it's enabled? v.configureVIPs() return }
[ "func", "(", "v", "*", "vserver", ")", "configUpdate", "(", ")", "{", "newSvcs", ":=", "v", ".", "expandServices", "(", ")", "\n", "for", "svcKey", ",", "newSvc", ":=", "range", "newSvcs", "{", "if", "svc", ",", "ok", ":=", "v", ".", "services", "[", "svcKey", "]", ";", "ok", "{", "if", "svc", ".", "ip", ".", "Equal", "(", "newSvc", ".", "ip", ")", "{", "svc", ".", "update", "(", "newSvc", ")", "\n", "continue", "\n", "}", "\n", "log", ".", "Infof", "(", "\"%v: service %v: new IP address: %v\"", ",", "v", ",", "svc", ",", "newSvc", ".", "ip", ")", "\n", "v", ".", "deleteService", "(", "svc", ")", "\n", "}", "\n", "log", ".", "Infof", "(", "\"%v: adding new service: %v\"", ",", "v", ",", "newSvc", ")", "\n", "v", ".", "services", "[", "svcKey", "]", "=", "newSvc", "\n", "v", ".", "updateState", "(", "newSvc", ".", "ip", ")", "\n", "}", "\n", "for", "svcKey", ",", "svc", ":=", "range", "v", ".", "services", "{", "if", "newSvcs", "[", "svcKey", "]", "==", "nil", "{", "v", ".", "deleteService", "(", "svc", ")", "\n", "continue", "\n", "}", "\n", "newDests", ":=", "v", ".", "expandDests", "(", "svc", ")", "\n", "for", "destKey", ",", "newDest", ":=", "range", "newDests", "{", "if", "dest", ",", "ok", ":=", "svc", ".", "dests", "[", "destKey", "]", ";", "ok", "{", "dest", ".", "update", "(", "newDest", ")", "\n", "continue", "\n", "}", "\n", "log", ".", "Infof", "(", "\"%v: service %v: adding new destination: %v\"", ",", "v", ",", "svc", ",", "newDest", ")", "\n", "svc", ".", "dests", "[", "destKey", "]", "=", "newDest", "\n", "}", "\n", "for", "destKey", ",", "dest", ":=", "range", "svc", ".", "dests", "{", "if", "newDests", "[", "destKey", "]", "==", "nil", "{", "if", "dest", ".", "active", "{", "dest", ".", "healthy", "=", "false", "\n", "svc", ".", "updateState", "(", ")", "\n", "}", "\n", "log", ".", "Infof", "(", "\"%v: service %v: deleting destination: %v\"", ",", "v", ",", "svc", ",", "dest", ")", "\n", "delete", "(", "svc", ".", "dests", ",", "destKey", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "needVIPs", ":=", "make", "(", "map", "[", "seesaw", ".", "IP", "]", "bool", ")", "\n", "for", "_", ",", "svc", ":=", "range", "v", ".", "services", "{", "needVIPs", "[", "svc", ".", "ip", "]", "=", "true", "\n", "}", "\n", "for", "vip", ":=", "range", "v", ".", "vips", "{", "if", "!", "needVIPs", "[", "vip", ".", "IP", "]", "{", "log", ".", "Infof", "(", "\"%v: unconfiguring no longer needed VIP %v\"", ",", "v", ",", "vip", ".", "IP", ")", "\n", "v", ".", "unconfigureVIP", "(", "&", "vip", ")", "\n", "}", "\n", "}", "\n", "checks", ":=", "v", ".", "expandChecks", "(", ")", "\n", "for", "k", ",", "oldCheck", ":=", "range", "v", ".", "checks", "{", "if", "checks", "[", "k", "]", "!=", "nil", "{", "checks", "[", "k", "]", ".", "description", "=", "oldCheck", ".", "description", "\n", "checks", "[", "k", "]", ".", "status", "=", "oldCheck", ".", "status", "\n", "}", "\n", "}", "\n", "v", ".", "checks", "=", "checks", "\n", "v", ".", "configureVIPs", "(", ")", "\n", "return", "\n", "}" ]
// configUpdate updates the services, destinations, checks, and VIPs for a // vserver.
[ "configUpdate", "updates", "the", "services", "destinations", "checks", "and", "VIPs", "for", "a", "vserver", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/vserver.go#L641-L712
train
google/seesaw
engine/vserver.go
deleteService
func (v *vserver) deleteService(s *service) { if s.active { s.healthy = false v.updateState(s.ip) } log.Infof("%v: deleting service: %v", v, s) delete(v.services, s.serviceKey) // TODO(baptr): Once service contains seesaw.VIP, move check and // unconfigureVIP here. }
go
func (v *vserver) deleteService(s *service) { if s.active { s.healthy = false v.updateState(s.ip) } log.Infof("%v: deleting service: %v", v, s) delete(v.services, s.serviceKey) // TODO(baptr): Once service contains seesaw.VIP, move check and // unconfigureVIP here. }
[ "func", "(", "v", "*", "vserver", ")", "deleteService", "(", "s", "*", "service", ")", "{", "if", "s", ".", "active", "{", "s", ".", "healthy", "=", "false", "\n", "v", ".", "updateState", "(", "s", ".", "ip", ")", "\n", "}", "\n", "log", ".", "Infof", "(", "\"%v: deleting service: %v\"", ",", "v", ",", "s", ")", "\n", "delete", "(", "v", ".", "services", ",", "s", ".", "serviceKey", ")", "\n", "}" ]
// deleteService deletes a service for a vserver.
[ "deleteService", "deletes", "a", "service", "for", "a", "vserver", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/vserver.go#L715-L724
train
google/seesaw
engine/vserver.go
handleCheckNotification
func (v *vserver) handleCheckNotification(n *checkNotification) { if !v.enabled { log.Infof("%v: ignoring healthcheck notification %s (vserver disabled)", v, n.description) return } check := v.checks[n.key] if check == nil { log.Warningf("%v: unknown check key %v", v, n.key) return } transition := (check.status.State != n.status.State) check.description = n.description check.status = n.status if transition { log.Infof("%v: healthcheck %s - %v (%s)", v, n.description, n.status.State, n.status.Message) for _, d := range check.dests { d.updateState() } } }
go
func (v *vserver) handleCheckNotification(n *checkNotification) { if !v.enabled { log.Infof("%v: ignoring healthcheck notification %s (vserver disabled)", v, n.description) return } check := v.checks[n.key] if check == nil { log.Warningf("%v: unknown check key %v", v, n.key) return } transition := (check.status.State != n.status.State) check.description = n.description check.status = n.status if transition { log.Infof("%v: healthcheck %s - %v (%s)", v, n.description, n.status.State, n.status.Message) for _, d := range check.dests { d.updateState() } } }
[ "func", "(", "v", "*", "vserver", ")", "handleCheckNotification", "(", "n", "*", "checkNotification", ")", "{", "if", "!", "v", ".", "enabled", "{", "log", ".", "Infof", "(", "\"%v: ignoring healthcheck notification %s (vserver disabled)\"", ",", "v", ",", "n", ".", "description", ")", "\n", "return", "\n", "}", "\n", "check", ":=", "v", ".", "checks", "[", "n", ".", "key", "]", "\n", "if", "check", "==", "nil", "{", "log", ".", "Warningf", "(", "\"%v: unknown check key %v\"", ",", "v", ",", "n", ".", "key", ")", "\n", "return", "\n", "}", "\n", "transition", ":=", "(", "check", ".", "status", ".", "State", "!=", "n", ".", "status", ".", "State", ")", "\n", "check", ".", "description", "=", "n", ".", "description", "\n", "check", ".", "status", "=", "n", ".", "status", "\n", "if", "transition", "{", "log", ".", "Infof", "(", "\"%v: healthcheck %s - %v (%s)\"", ",", "v", ",", "n", ".", "description", ",", "n", ".", "status", ".", "State", ",", "n", ".", "status", ".", "Message", ")", "\n", "for", "_", ",", "d", ":=", "range", "check", ".", "dests", "{", "d", ".", "updateState", "(", ")", "\n", "}", "\n", "}", "\n", "}" ]
// handleCheckNotification processes a checkNotification, bringing // destinations, services, and vservers up or down appropriately.
[ "handleCheckNotification", "processes", "a", "checkNotification", "bringing", "destinations", "services", "and", "vservers", "up", "or", "down", "appropriately", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/vserver.go#L728-L749
train
google/seesaw
engine/vserver.go
handleOverride
func (v *vserver) handleOverride(o seesaw.Override) { switch override := o.(type) { case *seesaw.VserverOverride: if v.vserverOverride == *override { // No change return } v.vserverOverride = *override if vserverEnabled(v.config, o.State()) == v.enabled { // enable state not changed - nothing to do return } // TODO(angusc): handle backend and destination overrides. default: return } if v.config != nil { v.handleConfigUpdate(v.config) } }
go
func (v *vserver) handleOverride(o seesaw.Override) { switch override := o.(type) { case *seesaw.VserverOverride: if v.vserverOverride == *override { // No change return } v.vserverOverride = *override if vserverEnabled(v.config, o.State()) == v.enabled { // enable state not changed - nothing to do return } // TODO(angusc): handle backend and destination overrides. default: return } if v.config != nil { v.handleConfigUpdate(v.config) } }
[ "func", "(", "v", "*", "vserver", ")", "handleOverride", "(", "o", "seesaw", ".", "Override", ")", "{", "switch", "override", ":=", "o", ".", "(", "type", ")", "{", "case", "*", "seesaw", ".", "VserverOverride", ":", "if", "v", ".", "vserverOverride", "==", "*", "override", "{", "return", "\n", "}", "\n", "v", ".", "vserverOverride", "=", "*", "override", "\n", "if", "vserverEnabled", "(", "v", ".", "config", ",", "o", ".", "State", "(", ")", ")", "==", "v", ".", "enabled", "{", "return", "\n", "}", "\n", "default", ":", "return", "\n", "}", "\n", "if", "v", ".", "config", "!=", "nil", "{", "v", ".", "handleConfigUpdate", "(", "v", ".", "config", ")", "\n", "}", "\n", "}" ]
// handleOverride processes an Override.
[ "handleOverride", "processes", "an", "Override", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/vserver.go#L752-L771
train
google/seesaw
engine/vserver.go
vserverEnabled
func vserverEnabled(config *config.Vserver, os seesaw.OverrideState) bool { switch { case config == nil: return false case os == seesaw.OverrideDisable: return false case os == seesaw.OverrideEnable: return true } return config.Enabled }
go
func vserverEnabled(config *config.Vserver, os seesaw.OverrideState) bool { switch { case config == nil: return false case os == seesaw.OverrideDisable: return false case os == seesaw.OverrideEnable: return true } return config.Enabled }
[ "func", "vserverEnabled", "(", "config", "*", "config", ".", "Vserver", ",", "os", "seesaw", ".", "OverrideState", ")", "bool", "{", "switch", "{", "case", "config", "==", "nil", ":", "return", "false", "\n", "case", "os", "==", "seesaw", ".", "OverrideDisable", ":", "return", "false", "\n", "case", "os", "==", "seesaw", ".", "OverrideEnable", ":", "return", "true", "\n", "}", "\n", "return", "config", ".", "Enabled", "\n", "}" ]
// vserverEnabled returns true if a vserver having the given configuration // and override state should be enabled.
[ "vserverEnabled", "returns", "true", "if", "a", "vserver", "having", "the", "given", "configuration", "and", "override", "state", "should", "be", "enabled", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/vserver.go#L775-L785
train
google/seesaw
engine/vserver.go
snapshot
func (v *vserver) snapshot() *seesaw.Vserver { if v.config == nil { return nil } sv := &seesaw.Vserver{ Name: v.config.Name, Entries: make([]*seesaw.VserverEntry, 0, len(v.config.Entries)), Host: seesaw.Host{ Hostname: v.config.Hostname, IPv4Addr: v.config.IPv4Addr, IPv4Mask: v.config.IPv4Mask, IPv6Addr: v.config.IPv6Addr, IPv6Mask: v.config.IPv6Mask, }, FWM: make(map[seesaw.AF]uint32), Services: make(map[seesaw.ServiceKey]*seesaw.Service, len(v.services)), OverrideState: v.vserverOverride.State(), Enabled: v.enabled, ConfigEnabled: v.config.Enabled, Warnings: v.config.Warnings, } for _, ve := range v.config.Entries { sv.Entries = append(sv.Entries, ve.Snapshot()) } sv.FWM[seesaw.IPv4] = v.fwm[seesaw.IPv4] sv.FWM[seesaw.IPv6] = v.fwm[seesaw.IPv6] for _, s := range v.services { ss := s.snapshot() sv.Services[ss.ServiceKey] = ss } return sv }
go
func (v *vserver) snapshot() *seesaw.Vserver { if v.config == nil { return nil } sv := &seesaw.Vserver{ Name: v.config.Name, Entries: make([]*seesaw.VserverEntry, 0, len(v.config.Entries)), Host: seesaw.Host{ Hostname: v.config.Hostname, IPv4Addr: v.config.IPv4Addr, IPv4Mask: v.config.IPv4Mask, IPv6Addr: v.config.IPv6Addr, IPv6Mask: v.config.IPv6Mask, }, FWM: make(map[seesaw.AF]uint32), Services: make(map[seesaw.ServiceKey]*seesaw.Service, len(v.services)), OverrideState: v.vserverOverride.State(), Enabled: v.enabled, ConfigEnabled: v.config.Enabled, Warnings: v.config.Warnings, } for _, ve := range v.config.Entries { sv.Entries = append(sv.Entries, ve.Snapshot()) } sv.FWM[seesaw.IPv4] = v.fwm[seesaw.IPv4] sv.FWM[seesaw.IPv6] = v.fwm[seesaw.IPv6] for _, s := range v.services { ss := s.snapshot() sv.Services[ss.ServiceKey] = ss } return sv }
[ "func", "(", "v", "*", "vserver", ")", "snapshot", "(", ")", "*", "seesaw", ".", "Vserver", "{", "if", "v", ".", "config", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "sv", ":=", "&", "seesaw", ".", "Vserver", "{", "Name", ":", "v", ".", "config", ".", "Name", ",", "Entries", ":", "make", "(", "[", "]", "*", "seesaw", ".", "VserverEntry", ",", "0", ",", "len", "(", "v", ".", "config", ".", "Entries", ")", ")", ",", "Host", ":", "seesaw", ".", "Host", "{", "Hostname", ":", "v", ".", "config", ".", "Hostname", ",", "IPv4Addr", ":", "v", ".", "config", ".", "IPv4Addr", ",", "IPv4Mask", ":", "v", ".", "config", ".", "IPv4Mask", ",", "IPv6Addr", ":", "v", ".", "config", ".", "IPv6Addr", ",", "IPv6Mask", ":", "v", ".", "config", ".", "IPv6Mask", ",", "}", ",", "FWM", ":", "make", "(", "map", "[", "seesaw", ".", "AF", "]", "uint32", ")", ",", "Services", ":", "make", "(", "map", "[", "seesaw", ".", "ServiceKey", "]", "*", "seesaw", ".", "Service", ",", "len", "(", "v", ".", "services", ")", ")", ",", "OverrideState", ":", "v", ".", "vserverOverride", ".", "State", "(", ")", ",", "Enabled", ":", "v", ".", "enabled", ",", "ConfigEnabled", ":", "v", ".", "config", ".", "Enabled", ",", "Warnings", ":", "v", ".", "config", ".", "Warnings", ",", "}", "\n", "for", "_", ",", "ve", ":=", "range", "v", ".", "config", ".", "Entries", "{", "sv", ".", "Entries", "=", "append", "(", "sv", ".", "Entries", ",", "ve", ".", "Snapshot", "(", ")", ")", "\n", "}", "\n", "sv", ".", "FWM", "[", "seesaw", ".", "IPv4", "]", "=", "v", ".", "fwm", "[", "seesaw", ".", "IPv4", "]", "\n", "sv", ".", "FWM", "[", "seesaw", ".", "IPv6", "]", "=", "v", ".", "fwm", "[", "seesaw", ".", "IPv6", "]", "\n", "for", "_", ",", "s", ":=", "range", "v", ".", "services", "{", "ss", ":=", "s", ".", "snapshot", "(", ")", "\n", "sv", ".", "Services", "[", "ss", ".", "ServiceKey", "]", "=", "ss", "\n", "}", "\n", "return", "sv", "\n", "}" ]
// snapshot exports the current running state of the vserver.
[ "snapshot", "exports", "the", "current", "running", "state", "of", "the", "vserver", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/vserver.go#L788-L819
train
google/seesaw
engine/vserver.go
updateState
func (d *destination) updateState() { // The destination is healthy if the backend is enabled and *all* the checks // for that destination are healthy. healthy := d.backend.Enabled if healthy { for _, c := range d.checks { if c.status.State != healthcheck.StateHealthy { healthy = false break } } } if d.healthy == healthy { return } d.healthy = healthy switch { case d.service.active && d.healthy: // The service is already active. Bringing up the dest will have no effect // on the service or vserver state. d.up() case d.service.active != d.healthy || d.service.healthy != d.healthy: // The service may need to be brought up or down. d.service.updateState() } }
go
func (d *destination) updateState() { // The destination is healthy if the backend is enabled and *all* the checks // for that destination are healthy. healthy := d.backend.Enabled if healthy { for _, c := range d.checks { if c.status.State != healthcheck.StateHealthy { healthy = false break } } } if d.healthy == healthy { return } d.healthy = healthy switch { case d.service.active && d.healthy: // The service is already active. Bringing up the dest will have no effect // on the service or vserver state. d.up() case d.service.active != d.healthy || d.service.healthy != d.healthy: // The service may need to be brought up or down. d.service.updateState() } }
[ "func", "(", "d", "*", "destination", ")", "updateState", "(", ")", "{", "healthy", ":=", "d", ".", "backend", ".", "Enabled", "\n", "if", "healthy", "{", "for", "_", ",", "c", ":=", "range", "d", ".", "checks", "{", "if", "c", ".", "status", ".", "State", "!=", "healthcheck", ".", "StateHealthy", "{", "healthy", "=", "false", "\n", "break", "\n", "}", "\n", "}", "\n", "}", "\n", "if", "d", ".", "healthy", "==", "healthy", "{", "return", "\n", "}", "\n", "d", ".", "healthy", "=", "healthy", "\n", "switch", "{", "case", "d", ".", "service", ".", "active", "&&", "d", ".", "healthy", ":", "d", ".", "up", "(", ")", "\n", "case", "d", ".", "service", ".", "active", "!=", "d", ".", "healthy", "||", "d", ".", "service", ".", "healthy", "!=", "d", ".", "healthy", ":", "d", ".", "service", ".", "updateState", "(", ")", "\n", "}", "\n", "}" ]
// updateState updates the state of a destination based on the state of checks // and propagates state changes to the service level if necessary.
[ "updateState", "updates", "the", "state", "of", "a", "destination", "based", "on", "the", "state", "of", "checks", "and", "propagates", "state", "changes", "to", "the", "service", "level", "if", "necessary", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/vserver.go#L823-L851
train
google/seesaw
engine/vserver.go
up
func (d *destination) up() { d.active = true log.Infof("%v: %v backend %v up", d.service.vserver, d.service, d) ncc := d.service.vserver.ncc if err := ncc.Dial(); err != nil { log.Fatalf("%v: failed to connect to NCC: %v", d.service.vserver, err) } defer ncc.Close() if err := ncc.IPVSAddDestination(d.service.ipvsSvc, d.ipvsDst); err != nil { log.Fatalf("%v: failed to add destination %v: %v", d.service.vserver, d, err) } }
go
func (d *destination) up() { d.active = true log.Infof("%v: %v backend %v up", d.service.vserver, d.service, d) ncc := d.service.vserver.ncc if err := ncc.Dial(); err != nil { log.Fatalf("%v: failed to connect to NCC: %v", d.service.vserver, err) } defer ncc.Close() if err := ncc.IPVSAddDestination(d.service.ipvsSvc, d.ipvsDst); err != nil { log.Fatalf("%v: failed to add destination %v: %v", d.service.vserver, d, err) } }
[ "func", "(", "d", "*", "destination", ")", "up", "(", ")", "{", "d", ".", "active", "=", "true", "\n", "log", ".", "Infof", "(", "\"%v: %v backend %v up\"", ",", "d", ".", "service", ".", "vserver", ",", "d", ".", "service", ",", "d", ")", "\n", "ncc", ":=", "d", ".", "service", ".", "vserver", ".", "ncc", "\n", "if", "err", ":=", "ncc", ".", "Dial", "(", ")", ";", "err", "!=", "nil", "{", "log", ".", "Fatalf", "(", "\"%v: failed to connect to NCC: %v\"", ",", "d", ".", "service", ".", "vserver", ",", "err", ")", "\n", "}", "\n", "defer", "ncc", ".", "Close", "(", ")", "\n", "if", "err", ":=", "ncc", ".", "IPVSAddDestination", "(", "d", ".", "service", ".", "ipvsSvc", ",", "d", ".", "ipvsDst", ")", ";", "err", "!=", "nil", "{", "log", ".", "Fatalf", "(", "\"%v: failed to add destination %v: %v\"", ",", "d", ".", "service", ".", "vserver", ",", "d", ",", "err", ")", "\n", "}", "\n", "}" ]
// up brings up a destination.
[ "up", "brings", "up", "a", "destination", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/vserver.go#L854-L866
train
google/seesaw
engine/vserver.go
down
func (d *destination) down() { d.active = false log.Infof("%v: %v backend %v down", d.service.vserver, d.service, d) ncc := d.service.vserver.ncc if err := ncc.Dial(); err != nil { log.Fatalf("%v: failed to connect to NCC: %v", d.service.vserver, err) } defer ncc.Close() if err := ncc.IPVSDeleteDestination(d.service.ipvsSvc, d.ipvsDst); err != nil { log.Fatalf("%v: failed to delete destination %v: %v", d.service.vserver, d, err) } }
go
func (d *destination) down() { d.active = false log.Infof("%v: %v backend %v down", d.service.vserver, d.service, d) ncc := d.service.vserver.ncc if err := ncc.Dial(); err != nil { log.Fatalf("%v: failed to connect to NCC: %v", d.service.vserver, err) } defer ncc.Close() if err := ncc.IPVSDeleteDestination(d.service.ipvsSvc, d.ipvsDst); err != nil { log.Fatalf("%v: failed to delete destination %v: %v", d.service.vserver, d, err) } }
[ "func", "(", "d", "*", "destination", ")", "down", "(", ")", "{", "d", ".", "active", "=", "false", "\n", "log", ".", "Infof", "(", "\"%v: %v backend %v down\"", ",", "d", ".", "service", ".", "vserver", ",", "d", ".", "service", ",", "d", ")", "\n", "ncc", ":=", "d", ".", "service", ".", "vserver", ".", "ncc", "\n", "if", "err", ":=", "ncc", ".", "Dial", "(", ")", ";", "err", "!=", "nil", "{", "log", ".", "Fatalf", "(", "\"%v: failed to connect to NCC: %v\"", ",", "d", ".", "service", ".", "vserver", ",", "err", ")", "\n", "}", "\n", "defer", "ncc", ".", "Close", "(", ")", "\n", "if", "err", ":=", "ncc", ".", "IPVSDeleteDestination", "(", "d", ".", "service", ".", "ipvsSvc", ",", "d", ".", "ipvsDst", ")", ";", "err", "!=", "nil", "{", "log", ".", "Fatalf", "(", "\"%v: failed to delete destination %v: %v\"", ",", "d", ".", "service", ".", "vserver", ",", "d", ",", "err", ")", "\n", "}", "\n", "}" ]
// down takes down a destination.
[ "down", "takes", "down", "a", "destination", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/vserver.go#L869-L881
train
google/seesaw
engine/vserver.go
update
func (d *destination) update(dest *destination) { if d.destinationKey != dest.destinationKey { log.Fatalf("%v: can't update destination %v using %v: destinationKey mismatch: %v != %v", d.service.vserver, d, dest, d.destinationKey, dest.destinationKey) } log.Infof("%v: %v updating destination %v", d.service.vserver, d.service, d) updateIPVS := d.active && !d.ipvsEqual(dest) dest.active = d.active dest.healthy = d.healthy dest.stats = d.stats *d = *dest if !d.healthy { return } if !d.backend.Enabled { log.Infof("%v: %v disabling destination %v", d.service.vserver, d.service, d) d.healthy = false d.service.updateState() return } if !updateIPVS { return } log.Infof("%v: %v updating IPVS destination %v", d.service.vserver, d.service, d) ncc := d.service.vserver.ncc if err := ncc.Dial(); err != nil { log.Fatalf("%v: failed to connect to NCC: %v", d.service.vserver, err) } defer ncc.Close() if err := ncc.IPVSUpdateDestination(d.service.ipvsSvc, d.ipvsDst); err != nil { log.Fatalf("%v: failed to update destination %v: %v", d.service.vserver, d, err) } }
go
func (d *destination) update(dest *destination) { if d.destinationKey != dest.destinationKey { log.Fatalf("%v: can't update destination %v using %v: destinationKey mismatch: %v != %v", d.service.vserver, d, dest, d.destinationKey, dest.destinationKey) } log.Infof("%v: %v updating destination %v", d.service.vserver, d.service, d) updateIPVS := d.active && !d.ipvsEqual(dest) dest.active = d.active dest.healthy = d.healthy dest.stats = d.stats *d = *dest if !d.healthy { return } if !d.backend.Enabled { log.Infof("%v: %v disabling destination %v", d.service.vserver, d.service, d) d.healthy = false d.service.updateState() return } if !updateIPVS { return } log.Infof("%v: %v updating IPVS destination %v", d.service.vserver, d.service, d) ncc := d.service.vserver.ncc if err := ncc.Dial(); err != nil { log.Fatalf("%v: failed to connect to NCC: %v", d.service.vserver, err) } defer ncc.Close() if err := ncc.IPVSUpdateDestination(d.service.ipvsSvc, d.ipvsDst); err != nil { log.Fatalf("%v: failed to update destination %v: %v", d.service.vserver, d, err) } }
[ "func", "(", "d", "*", "destination", ")", "update", "(", "dest", "*", "destination", ")", "{", "if", "d", ".", "destinationKey", "!=", "dest", ".", "destinationKey", "{", "log", ".", "Fatalf", "(", "\"%v: can't update destination %v using %v: destinationKey mismatch: %v != %v\"", ",", "d", ".", "service", ".", "vserver", ",", "d", ",", "dest", ",", "d", ".", "destinationKey", ",", "dest", ".", "destinationKey", ")", "\n", "}", "\n", "log", ".", "Infof", "(", "\"%v: %v updating destination %v\"", ",", "d", ".", "service", ".", "vserver", ",", "d", ".", "service", ",", "d", ")", "\n", "updateIPVS", ":=", "d", ".", "active", "&&", "!", "d", ".", "ipvsEqual", "(", "dest", ")", "\n", "dest", ".", "active", "=", "d", ".", "active", "\n", "dest", ".", "healthy", "=", "d", ".", "healthy", "\n", "dest", ".", "stats", "=", "d", ".", "stats", "\n", "*", "d", "=", "*", "dest", "\n", "if", "!", "d", ".", "healthy", "{", "return", "\n", "}", "\n", "if", "!", "d", ".", "backend", ".", "Enabled", "{", "log", ".", "Infof", "(", "\"%v: %v disabling destination %v\"", ",", "d", ".", "service", ".", "vserver", ",", "d", ".", "service", ",", "d", ")", "\n", "d", ".", "healthy", "=", "false", "\n", "d", ".", "service", ".", "updateState", "(", ")", "\n", "return", "\n", "}", "\n", "if", "!", "updateIPVS", "{", "return", "\n", "}", "\n", "log", ".", "Infof", "(", "\"%v: %v updating IPVS destination %v\"", ",", "d", ".", "service", ".", "vserver", ",", "d", ".", "service", ",", "d", ")", "\n", "ncc", ":=", "d", ".", "service", ".", "vserver", ".", "ncc", "\n", "if", "err", ":=", "ncc", ".", "Dial", "(", ")", ";", "err", "!=", "nil", "{", "log", ".", "Fatalf", "(", "\"%v: failed to connect to NCC: %v\"", ",", "d", ".", "service", ".", "vserver", ",", "err", ")", "\n", "}", "\n", "defer", "ncc", ".", "Close", "(", ")", "\n", "if", "err", ":=", "ncc", ".", "IPVSUpdateDestination", "(", "d", ".", "service", ".", "ipvsSvc", ",", "d", ".", "ipvsDst", ")", ";", "err", "!=", "nil", "{", "log", ".", "Fatalf", "(", "\"%v: failed to update destination %v: %v\"", ",", "d", ".", "service", ".", "vserver", ",", "d", ",", "err", ")", "\n", "}", "\n", "}" ]
// update updates a destination while preserving its running state.
[ "update", "updates", "a", "destination", "while", "preserving", "its", "running", "state", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/vserver.go#L884-L923
train
google/seesaw
engine/vserver.go
snapshot
func (d *destination) snapshot() *seesaw.Destination { return &seesaw.Destination{ Backend: d.backend, Name: d.name(), VserverName: d.service.vserver.String(), Stats: d.stats, Enabled: d.backend.Enabled, Weight: d.weight, Healthy: d.healthy, Active: d.active, } }
go
func (d *destination) snapshot() *seesaw.Destination { return &seesaw.Destination{ Backend: d.backend, Name: d.name(), VserverName: d.service.vserver.String(), Stats: d.stats, Enabled: d.backend.Enabled, Weight: d.weight, Healthy: d.healthy, Active: d.active, } }
[ "func", "(", "d", "*", "destination", ")", "snapshot", "(", ")", "*", "seesaw", ".", "Destination", "{", "return", "&", "seesaw", ".", "Destination", "{", "Backend", ":", "d", ".", "backend", ",", "Name", ":", "d", ".", "name", "(", ")", ",", "VserverName", ":", "d", ".", "service", ".", "vserver", ".", "String", "(", ")", ",", "Stats", ":", "d", ".", "stats", ",", "Enabled", ":", "d", ".", "backend", ".", "Enabled", ",", "Weight", ":", "d", ".", "weight", ",", "Healthy", ":", "d", ".", "healthy", ",", "Active", ":", "d", ".", "active", ",", "}", "\n", "}" ]
// snapshot exports the current running state of a destination.
[ "snapshot", "exports", "the", "current", "running", "state", "of", "a", "destination", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/vserver.go#L926-L937
train
google/seesaw
engine/vserver.go
updateState
func (s *service) updateState() { // The service is considered healthy if: // 1) No watermarks are configured, and at least one destination is healthy. // OR // 2) (Num healthy dests) / (Num backends) >= high watermark. // OR // 3) Service is already healthy, and // (Num healthy dests) / (Num backends) >= low watermark. numBackends := 0 numHealthyDests := 0 for _, d := range s.dests { if d.backend.InService { numBackends++ } if d.healthy { numHealthyDests++ } } threshold := s.ventry.LowWatermark if !s.healthy { threshold = s.ventry.HighWatermark } var healthy bool switch { case numBackends == 0 || numHealthyDests == 0: healthy = false case threshold == 0.0: healthy = numHealthyDests >= 1 default: healthy = float32(numHealthyDests)/float32(numBackends) >= threshold } if s.healthy == healthy { // no change in service state, just update destinations s.updateDests() return } oldHealth := "unhealthy" newHealth := "unhealthy" if s.healthy { oldHealth = "healthy" } if healthy { newHealth = "healthy" } log.Infof("%v: %v: %d/%d destinations are healthy, service was %v, now %v", s.vserver, s, numHealthyDests, numBackends, oldHealth, newHealth) s.healthy = healthy vserverActive := s.vserver.active[s.ip] switch { case vserverActive && s.healthy: // The vserver is already active. Bringing up the service will have no // effect on the vserver state. s.up() case vserverActive != s.healthy: // The vserver may need to be brought up or down. s.vserver.updateState(s.ip) } }
go
func (s *service) updateState() { // The service is considered healthy if: // 1) No watermarks are configured, and at least one destination is healthy. // OR // 2) (Num healthy dests) / (Num backends) >= high watermark. // OR // 3) Service is already healthy, and // (Num healthy dests) / (Num backends) >= low watermark. numBackends := 0 numHealthyDests := 0 for _, d := range s.dests { if d.backend.InService { numBackends++ } if d.healthy { numHealthyDests++ } } threshold := s.ventry.LowWatermark if !s.healthy { threshold = s.ventry.HighWatermark } var healthy bool switch { case numBackends == 0 || numHealthyDests == 0: healthy = false case threshold == 0.0: healthy = numHealthyDests >= 1 default: healthy = float32(numHealthyDests)/float32(numBackends) >= threshold } if s.healthy == healthy { // no change in service state, just update destinations s.updateDests() return } oldHealth := "unhealthy" newHealth := "unhealthy" if s.healthy { oldHealth = "healthy" } if healthy { newHealth = "healthy" } log.Infof("%v: %v: %d/%d destinations are healthy, service was %v, now %v", s.vserver, s, numHealthyDests, numBackends, oldHealth, newHealth) s.healthy = healthy vserverActive := s.vserver.active[s.ip] switch { case vserverActive && s.healthy: // The vserver is already active. Bringing up the service will have no // effect on the vserver state. s.up() case vserverActive != s.healthy: // The vserver may need to be brought up or down. s.vserver.updateState(s.ip) } }
[ "func", "(", "s", "*", "service", ")", "updateState", "(", ")", "{", "numBackends", ":=", "0", "\n", "numHealthyDests", ":=", "0", "\n", "for", "_", ",", "d", ":=", "range", "s", ".", "dests", "{", "if", "d", ".", "backend", ".", "InService", "{", "numBackends", "++", "\n", "}", "\n", "if", "d", ".", "healthy", "{", "numHealthyDests", "++", "\n", "}", "\n", "}", "\n", "threshold", ":=", "s", ".", "ventry", ".", "LowWatermark", "\n", "if", "!", "s", ".", "healthy", "{", "threshold", "=", "s", ".", "ventry", ".", "HighWatermark", "\n", "}", "\n", "var", "healthy", "bool", "\n", "switch", "{", "case", "numBackends", "==", "0", "||", "numHealthyDests", "==", "0", ":", "healthy", "=", "false", "\n", "case", "threshold", "==", "0.0", ":", "healthy", "=", "numHealthyDests", ">=", "1", "\n", "default", ":", "healthy", "=", "float32", "(", "numHealthyDests", ")", "/", "float32", "(", "numBackends", ")", ">=", "threshold", "\n", "}", "\n", "if", "s", ".", "healthy", "==", "healthy", "{", "s", ".", "updateDests", "(", ")", "\n", "return", "\n", "}", "\n", "oldHealth", ":=", "\"unhealthy\"", "\n", "newHealth", ":=", "\"unhealthy\"", "\n", "if", "s", ".", "healthy", "{", "oldHealth", "=", "\"healthy\"", "\n", "}", "\n", "if", "healthy", "{", "newHealth", "=", "\"healthy\"", "\n", "}", "\n", "log", ".", "Infof", "(", "\"%v: %v: %d/%d destinations are healthy, service was %v, now %v\"", ",", "s", ".", "vserver", ",", "s", ",", "numHealthyDests", ",", "numBackends", ",", "oldHealth", ",", "newHealth", ")", "\n", "s", ".", "healthy", "=", "healthy", "\n", "vserverActive", ":=", "s", ".", "vserver", ".", "active", "[", "s", ".", "ip", "]", "\n", "switch", "{", "case", "vserverActive", "&&", "s", ".", "healthy", ":", "s", ".", "up", "(", ")", "\n", "case", "vserverActive", "!=", "s", ".", "healthy", ":", "s", ".", "vserver", ".", "updateState", "(", "s", ".", "ip", ")", "\n", "}", "\n", "}" ]
// updateState updates the state of a service based on the state of its // destinations and propagates state changes to the vserver level if necessary.
[ "updateState", "updates", "the", "state", "of", "a", "service", "based", "on", "the", "state", "of", "its", "destinations", "and", "propagates", "state", "changes", "to", "the", "vserver", "level", "if", "necessary", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/vserver.go#L941-L1005
train
google/seesaw
engine/vserver.go
updateDests
func (s *service) updateDests() { for _, d := range s.dests { if !s.active { d.stats.DestinationStats = &ipvs.DestinationStats{} if d.active { d.down() } continue } switch { case !d.healthy && d.active: d.down() case d.healthy && !d.active: d.up() } } }
go
func (s *service) updateDests() { for _, d := range s.dests { if !s.active { d.stats.DestinationStats = &ipvs.DestinationStats{} if d.active { d.down() } continue } switch { case !d.healthy && d.active: d.down() case d.healthy && !d.active: d.up() } } }
[ "func", "(", "s", "*", "service", ")", "updateDests", "(", ")", "{", "for", "_", ",", "d", ":=", "range", "s", ".", "dests", "{", "if", "!", "s", ".", "active", "{", "d", ".", "stats", ".", "DestinationStats", "=", "&", "ipvs", ".", "DestinationStats", "{", "}", "\n", "if", "d", ".", "active", "{", "d", ".", "down", "(", ")", "\n", "}", "\n", "continue", "\n", "}", "\n", "switch", "{", "case", "!", "d", ".", "healthy", "&&", "d", ".", "active", ":", "d", ".", "down", "(", ")", "\n", "case", "d", ".", "healthy", "&&", "!", "d", ".", "active", ":", "d", ".", "up", "(", ")", "\n", "}", "\n", "}", "\n", "}" ]
// updateDests brings the destinations for a service up or down based on the // state of the service and the health of each destination.
[ "updateDests", "brings", "the", "destinations", "for", "a", "service", "up", "or", "down", "based", "on", "the", "state", "of", "the", "service", "and", "the", "health", "of", "each", "destination", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/vserver.go#L1009-L1025
train
google/seesaw
engine/vserver.go
up
func (s *service) up() { s.active = true log.Infof("%v: %v service up", s.vserver, s) ncc := s.vserver.ncc if err := ncc.Dial(); err != nil { log.Fatalf("%v: failed to connect to NCC: %v", s.vserver, err) } defer ncc.Close() log.Infof("%v: adding IPVS service %v", s.vserver, s.ipvsSvc) if err := ncc.IPVSAddService(s.ipvsSvc); err != nil { log.Fatalf("%v: failed to add service %v: %v", s.vserver, s, err) } // Update destinations *after* the IPVS service exists. s.updateDests() }
go
func (s *service) up() { s.active = true log.Infof("%v: %v service up", s.vserver, s) ncc := s.vserver.ncc if err := ncc.Dial(); err != nil { log.Fatalf("%v: failed to connect to NCC: %v", s.vserver, err) } defer ncc.Close() log.Infof("%v: adding IPVS service %v", s.vserver, s.ipvsSvc) if err := ncc.IPVSAddService(s.ipvsSvc); err != nil { log.Fatalf("%v: failed to add service %v: %v", s.vserver, s, err) } // Update destinations *after* the IPVS service exists. s.updateDests() }
[ "func", "(", "s", "*", "service", ")", "up", "(", ")", "{", "s", ".", "active", "=", "true", "\n", "log", ".", "Infof", "(", "\"%v: %v service up\"", ",", "s", ".", "vserver", ",", "s", ")", "\n", "ncc", ":=", "s", ".", "vserver", ".", "ncc", "\n", "if", "err", ":=", "ncc", ".", "Dial", "(", ")", ";", "err", "!=", "nil", "{", "log", ".", "Fatalf", "(", "\"%v: failed to connect to NCC: %v\"", ",", "s", ".", "vserver", ",", "err", ")", "\n", "}", "\n", "defer", "ncc", ".", "Close", "(", ")", "\n", "log", ".", "Infof", "(", "\"%v: adding IPVS service %v\"", ",", "s", ".", "vserver", ",", "s", ".", "ipvsSvc", ")", "\n", "if", "err", ":=", "ncc", ".", "IPVSAddService", "(", "s", ".", "ipvsSvc", ")", ";", "err", "!=", "nil", "{", "log", ".", "Fatalf", "(", "\"%v: failed to add service %v: %v\"", ",", "s", ".", "vserver", ",", "s", ",", "err", ")", "\n", "}", "\n", "s", ".", "updateDests", "(", ")", "\n", "}" ]
// up brings up a service and all healthy destinations.
[ "up", "brings", "up", "a", "service", "and", "all", "healthy", "destinations", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/vserver.go#L1028-L1045
train
google/seesaw
engine/vserver.go
down
func (s *service) down() { s.active = false s.stats.ServiceStats = &ipvs.ServiceStats{} log.Infof("%v: %v service down", s.vserver, s) ncc := s.vserver.ncc if err := ncc.Dial(); err != nil { log.Fatalf("%v: failed to connect to NCC: %v", s.vserver, err) } defer ncc.Close() // Remove IPVS destinations *before* the IPVS service is removed. s.updateDests() if err := ncc.IPVSDeleteService(s.ipvsSvc); err != nil { log.Fatalf("%v: failed to delete service %v: %v", s.vserver, s, err) } }
go
func (s *service) down() { s.active = false s.stats.ServiceStats = &ipvs.ServiceStats{} log.Infof("%v: %v service down", s.vserver, s) ncc := s.vserver.ncc if err := ncc.Dial(); err != nil { log.Fatalf("%v: failed to connect to NCC: %v", s.vserver, err) } defer ncc.Close() // Remove IPVS destinations *before* the IPVS service is removed. s.updateDests() if err := ncc.IPVSDeleteService(s.ipvsSvc); err != nil { log.Fatalf("%v: failed to delete service %v: %v", s.vserver, s, err) } }
[ "func", "(", "s", "*", "service", ")", "down", "(", ")", "{", "s", ".", "active", "=", "false", "\n", "s", ".", "stats", ".", "ServiceStats", "=", "&", "ipvs", ".", "ServiceStats", "{", "}", "\n", "log", ".", "Infof", "(", "\"%v: %v service down\"", ",", "s", ".", "vserver", ",", "s", ")", "\n", "ncc", ":=", "s", ".", "vserver", ".", "ncc", "\n", "if", "err", ":=", "ncc", ".", "Dial", "(", ")", ";", "err", "!=", "nil", "{", "log", ".", "Fatalf", "(", "\"%v: failed to connect to NCC: %v\"", ",", "s", ".", "vserver", ",", "err", ")", "\n", "}", "\n", "defer", "ncc", ".", "Close", "(", ")", "\n", "s", ".", "updateDests", "(", ")", "\n", "if", "err", ":=", "ncc", ".", "IPVSDeleteService", "(", "s", ".", "ipvsSvc", ")", ";", "err", "!=", "nil", "{", "log", ".", "Fatalf", "(", "\"%v: failed to delete service %v: %v\"", ",", "s", ".", "vserver", ",", "s", ",", "err", ")", "\n", "}", "\n", "}" ]
// down takes down all destinations for a service, then takes down the // service.
[ "down", "takes", "down", "all", "destinations", "for", "a", "service", "then", "takes", "down", "the", "service", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/vserver.go#L1049-L1066
train
google/seesaw
engine/vserver.go
update
func (s *service) update(svc *service) { if s.serviceKey != svc.serviceKey { log.Fatalf("%v: can't update service %v using %v: serviceKey mismatch: %v != %v", s.vserver, s, svc, s.serviceKey, svc.serviceKey) } log.Infof("%v: updating service %v", s.vserver, s) updateIPVS := s.active && !s.ipvsEqual(svc) svc.active = s.active svc.healthy = s.healthy svc.stats = s.stats svc.dests = s.dests *s = *svc if !updateIPVS { return } log.Infof("%v: %v updating IPVS service", s.vserver, s) ncc := s.vserver.ncc if err := ncc.Dial(); err != nil { log.Fatalf("%v: failed to connect to NCC: %v", s.vserver, err) } defer ncc.Close() if err := ncc.IPVSUpdateService(s.ipvsSvc); err != nil { log.Fatalf("%v: failed to update service %v: %v", s.vserver, s, err) } }
go
func (s *service) update(svc *service) { if s.serviceKey != svc.serviceKey { log.Fatalf("%v: can't update service %v using %v: serviceKey mismatch: %v != %v", s.vserver, s, svc, s.serviceKey, svc.serviceKey) } log.Infof("%v: updating service %v", s.vserver, s) updateIPVS := s.active && !s.ipvsEqual(svc) svc.active = s.active svc.healthy = s.healthy svc.stats = s.stats svc.dests = s.dests *s = *svc if !updateIPVS { return } log.Infof("%v: %v updating IPVS service", s.vserver, s) ncc := s.vserver.ncc if err := ncc.Dial(); err != nil { log.Fatalf("%v: failed to connect to NCC: %v", s.vserver, err) } defer ncc.Close() if err := ncc.IPVSUpdateService(s.ipvsSvc); err != nil { log.Fatalf("%v: failed to update service %v: %v", s.vserver, s, err) } }
[ "func", "(", "s", "*", "service", ")", "update", "(", "svc", "*", "service", ")", "{", "if", "s", ".", "serviceKey", "!=", "svc", ".", "serviceKey", "{", "log", ".", "Fatalf", "(", "\"%v: can't update service %v using %v: serviceKey mismatch: %v != %v\"", ",", "s", ".", "vserver", ",", "s", ",", "svc", ",", "s", ".", "serviceKey", ",", "svc", ".", "serviceKey", ")", "\n", "}", "\n", "log", ".", "Infof", "(", "\"%v: updating service %v\"", ",", "s", ".", "vserver", ",", "s", ")", "\n", "updateIPVS", ":=", "s", ".", "active", "&&", "!", "s", ".", "ipvsEqual", "(", "svc", ")", "\n", "svc", ".", "active", "=", "s", ".", "active", "\n", "svc", ".", "healthy", "=", "s", ".", "healthy", "\n", "svc", ".", "stats", "=", "s", ".", "stats", "\n", "svc", ".", "dests", "=", "s", ".", "dests", "\n", "*", "s", "=", "*", "svc", "\n", "if", "!", "updateIPVS", "{", "return", "\n", "}", "\n", "log", ".", "Infof", "(", "\"%v: %v updating IPVS service\"", ",", "s", ".", "vserver", ",", "s", ")", "\n", "ncc", ":=", "s", ".", "vserver", ".", "ncc", "\n", "if", "err", ":=", "ncc", ".", "Dial", "(", ")", ";", "err", "!=", "nil", "{", "log", ".", "Fatalf", "(", "\"%v: failed to connect to NCC: %v\"", ",", "s", ".", "vserver", ",", "err", ")", "\n", "}", "\n", "defer", "ncc", ".", "Close", "(", ")", "\n", "if", "err", ":=", "ncc", ".", "IPVSUpdateService", "(", "s", ".", "ipvsSvc", ")", ";", "err", "!=", "nil", "{", "log", ".", "Fatalf", "(", "\"%v: failed to update service %v: %v\"", ",", "s", ".", "vserver", ",", "s", ",", "err", ")", "\n", "}", "\n", "}" ]
// update updates a service while preserving its running state.
[ "update", "updates", "a", "service", "while", "preserving", "its", "running", "state", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/vserver.go#L1069-L1097
train
google/seesaw
engine/vserver.go
updateStats
func (s *service) updateStats() { if !s.active { return } log.V(1).Infof("%v: updating IPVS statistics for %v", s.vserver, s) ncc := s.vserver.ncc if err := ncc.Dial(); err != nil { log.Fatalf("%v: failed to connect to NCC: %v", s.vserver, err) } defer ncc.Close() ipvsSvc, err := ncc.IPVSGetService(s.ipvsSvc) if err != nil { log.Warningf("%v: failed to get statistics for %v: %v", s.vserver, s, err) return } s.stats.ServiceStats = ipvsSvc.Statistics for _, ipvsDst := range ipvsSvc.Destinations { found := false for _, d := range s.dests { if d.ipvsDst.Address.Equal(ipvsDst.Address) && d.ipvsDst.Port == ipvsDst.Port { d.stats.DestinationStats = ipvsDst.Statistics found = true break } } if !found { log.Warningf("%v: got statistics for unknown destination %v", s.vserver, ipvsDst) } } }
go
func (s *service) updateStats() { if !s.active { return } log.V(1).Infof("%v: updating IPVS statistics for %v", s.vserver, s) ncc := s.vserver.ncc if err := ncc.Dial(); err != nil { log.Fatalf("%v: failed to connect to NCC: %v", s.vserver, err) } defer ncc.Close() ipvsSvc, err := ncc.IPVSGetService(s.ipvsSvc) if err != nil { log.Warningf("%v: failed to get statistics for %v: %v", s.vserver, s, err) return } s.stats.ServiceStats = ipvsSvc.Statistics for _, ipvsDst := range ipvsSvc.Destinations { found := false for _, d := range s.dests { if d.ipvsDst.Address.Equal(ipvsDst.Address) && d.ipvsDst.Port == ipvsDst.Port { d.stats.DestinationStats = ipvsDst.Statistics found = true break } } if !found { log.Warningf("%v: got statistics for unknown destination %v", s.vserver, ipvsDst) } } }
[ "func", "(", "s", "*", "service", ")", "updateStats", "(", ")", "{", "if", "!", "s", ".", "active", "{", "return", "\n", "}", "\n", "log", ".", "V", "(", "1", ")", ".", "Infof", "(", "\"%v: updating IPVS statistics for %v\"", ",", "s", ".", "vserver", ",", "s", ")", "\n", "ncc", ":=", "s", ".", "vserver", ".", "ncc", "\n", "if", "err", ":=", "ncc", ".", "Dial", "(", ")", ";", "err", "!=", "nil", "{", "log", ".", "Fatalf", "(", "\"%v: failed to connect to NCC: %v\"", ",", "s", ".", "vserver", ",", "err", ")", "\n", "}", "\n", "defer", "ncc", ".", "Close", "(", ")", "\n", "ipvsSvc", ",", "err", ":=", "ncc", ".", "IPVSGetService", "(", "s", ".", "ipvsSvc", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Warningf", "(", "\"%v: failed to get statistics for %v: %v\"", ",", "s", ".", "vserver", ",", "s", ",", "err", ")", "\n", "return", "\n", "}", "\n", "s", ".", "stats", ".", "ServiceStats", "=", "ipvsSvc", ".", "Statistics", "\n", "for", "_", ",", "ipvsDst", ":=", "range", "ipvsSvc", ".", "Destinations", "{", "found", ":=", "false", "\n", "for", "_", ",", "d", ":=", "range", "s", ".", "dests", "{", "if", "d", ".", "ipvsDst", ".", "Address", ".", "Equal", "(", "ipvsDst", ".", "Address", ")", "&&", "d", ".", "ipvsDst", ".", "Port", "==", "ipvsDst", ".", "Port", "{", "d", ".", "stats", ".", "DestinationStats", "=", "ipvsDst", ".", "Statistics", "\n", "found", "=", "true", "\n", "break", "\n", "}", "\n", "}", "\n", "if", "!", "found", "{", "log", ".", "Warningf", "(", "\"%v: got statistics for unknown destination %v\"", ",", "s", ".", "vserver", ",", "ipvsDst", ")", "\n", "}", "\n", "}", "\n", "}" ]
// updateStats updates the IPVS statistics for this service.
[ "updateStats", "updates", "the", "IPVS", "statistics", "for", "this", "service", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/vserver.go#L1100-L1133
train
google/seesaw
engine/vserver.go
snapshot
func (s *service) snapshot() *seesaw.Service { ss := &seesaw.Service{ ServiceKey: seesaw.ServiceKey{ AF: s.af, Proto: s.proto, Port: s.port, }, Mode: s.ventry.Mode, Scheduler: s.ventry.Scheduler, OnePacket: s.ventry.OnePacket, Persistence: s.ventry.Persistence, IP: s.ip.IP(), Healthy: s.healthy, Enabled: s.vserver.enabled, Active: s.active, Stats: s.stats, Destinations: make(map[string]*seesaw.Destination), LowWatermark: s.ventry.LowWatermark, HighWatermark: s.ventry.HighWatermark, } for _, d := range s.dests { sd := d.snapshot() ss.Destinations[sd.Backend.Hostname] = sd } numBackends := 0 numHealthyDests := 0 for _, d := range s.dests { if d.backend.InService { numBackends++ } if d.healthy { numHealthyDests++ } } if numBackends > 0 { ss.CurrentWatermark = float32(numHealthyDests) / float32(numBackends) } return ss }
go
func (s *service) snapshot() *seesaw.Service { ss := &seesaw.Service{ ServiceKey: seesaw.ServiceKey{ AF: s.af, Proto: s.proto, Port: s.port, }, Mode: s.ventry.Mode, Scheduler: s.ventry.Scheduler, OnePacket: s.ventry.OnePacket, Persistence: s.ventry.Persistence, IP: s.ip.IP(), Healthy: s.healthy, Enabled: s.vserver.enabled, Active: s.active, Stats: s.stats, Destinations: make(map[string]*seesaw.Destination), LowWatermark: s.ventry.LowWatermark, HighWatermark: s.ventry.HighWatermark, } for _, d := range s.dests { sd := d.snapshot() ss.Destinations[sd.Backend.Hostname] = sd } numBackends := 0 numHealthyDests := 0 for _, d := range s.dests { if d.backend.InService { numBackends++ } if d.healthy { numHealthyDests++ } } if numBackends > 0 { ss.CurrentWatermark = float32(numHealthyDests) / float32(numBackends) } return ss }
[ "func", "(", "s", "*", "service", ")", "snapshot", "(", ")", "*", "seesaw", ".", "Service", "{", "ss", ":=", "&", "seesaw", ".", "Service", "{", "ServiceKey", ":", "seesaw", ".", "ServiceKey", "{", "AF", ":", "s", ".", "af", ",", "Proto", ":", "s", ".", "proto", ",", "Port", ":", "s", ".", "port", ",", "}", ",", "Mode", ":", "s", ".", "ventry", ".", "Mode", ",", "Scheduler", ":", "s", ".", "ventry", ".", "Scheduler", ",", "OnePacket", ":", "s", ".", "ventry", ".", "OnePacket", ",", "Persistence", ":", "s", ".", "ventry", ".", "Persistence", ",", "IP", ":", "s", ".", "ip", ".", "IP", "(", ")", ",", "Healthy", ":", "s", ".", "healthy", ",", "Enabled", ":", "s", ".", "vserver", ".", "enabled", ",", "Active", ":", "s", ".", "active", ",", "Stats", ":", "s", ".", "stats", ",", "Destinations", ":", "make", "(", "map", "[", "string", "]", "*", "seesaw", ".", "Destination", ")", ",", "LowWatermark", ":", "s", ".", "ventry", ".", "LowWatermark", ",", "HighWatermark", ":", "s", ".", "ventry", ".", "HighWatermark", ",", "}", "\n", "for", "_", ",", "d", ":=", "range", "s", ".", "dests", "{", "sd", ":=", "d", ".", "snapshot", "(", ")", "\n", "ss", ".", "Destinations", "[", "sd", ".", "Backend", ".", "Hostname", "]", "=", "sd", "\n", "}", "\n", "numBackends", ":=", "0", "\n", "numHealthyDests", ":=", "0", "\n", "for", "_", ",", "d", ":=", "range", "s", ".", "dests", "{", "if", "d", ".", "backend", ".", "InService", "{", "numBackends", "++", "\n", "}", "\n", "if", "d", ".", "healthy", "{", "numHealthyDests", "++", "\n", "}", "\n", "}", "\n", "if", "numBackends", ">", "0", "{", "ss", ".", "CurrentWatermark", "=", "float32", "(", "numHealthyDests", ")", "/", "float32", "(", "numBackends", ")", "\n", "}", "\n", "return", "ss", "\n", "}" ]
// snapshot exports the current running state of a service.
[ "snapshot", "exports", "the", "current", "running", "state", "of", "a", "service", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/vserver.go#L1136-L1176
train
google/seesaw
engine/vserver.go
updateState
func (v *vserver) updateState(ip seesaw.IP) { // A vserver anycast IP is healthy if *all* services for that IP are healthy. // A vserver unicast IP is healthy if *any* services for that IP are healthy. var healthy bool for _, s := range v.services { if !s.ip.Equal(ip) { continue } healthy = s.healthy if !healthy && seesaw.IsAnycast(ip.IP()) { break } if healthy && !seesaw.IsAnycast(ip.IP()) { break } } if v.active[ip] == healthy { v.updateServices(ip) return } switch { case !healthy && v.active[ip]: v.down(ip) case healthy && !v.active[ip]: v.up(ip) } }
go
func (v *vserver) updateState(ip seesaw.IP) { // A vserver anycast IP is healthy if *all* services for that IP are healthy. // A vserver unicast IP is healthy if *any* services for that IP are healthy. var healthy bool for _, s := range v.services { if !s.ip.Equal(ip) { continue } healthy = s.healthy if !healthy && seesaw.IsAnycast(ip.IP()) { break } if healthy && !seesaw.IsAnycast(ip.IP()) { break } } if v.active[ip] == healthy { v.updateServices(ip) return } switch { case !healthy && v.active[ip]: v.down(ip) case healthy && !v.active[ip]: v.up(ip) } }
[ "func", "(", "v", "*", "vserver", ")", "updateState", "(", "ip", "seesaw", ".", "IP", ")", "{", "var", "healthy", "bool", "\n", "for", "_", ",", "s", ":=", "range", "v", ".", "services", "{", "if", "!", "s", ".", "ip", ".", "Equal", "(", "ip", ")", "{", "continue", "\n", "}", "\n", "healthy", "=", "s", ".", "healthy", "\n", "if", "!", "healthy", "&&", "seesaw", ".", "IsAnycast", "(", "ip", ".", "IP", "(", ")", ")", "{", "break", "\n", "}", "\n", "if", "healthy", "&&", "!", "seesaw", ".", "IsAnycast", "(", "ip", ".", "IP", "(", ")", ")", "{", "break", "\n", "}", "\n", "}", "\n", "if", "v", ".", "active", "[", "ip", "]", "==", "healthy", "{", "v", ".", "updateServices", "(", "ip", ")", "\n", "return", "\n", "}", "\n", "switch", "{", "case", "!", "healthy", "&&", "v", ".", "active", "[", "ip", "]", ":", "v", ".", "down", "(", "ip", ")", "\n", "case", "healthy", "&&", "!", "v", ".", "active", "[", "ip", "]", ":", "v", ".", "up", "(", "ip", ")", "\n", "}", "\n", "}" ]
// updateState updates the state of an IP for a vserver based on the state of // that IP's services.
[ "updateState", "updates", "the", "state", "of", "an", "IP", "for", "a", "vserver", "based", "on", "the", "state", "of", "that", "IP", "s", "services", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/vserver.go#L1180-L1207
train
google/seesaw
engine/vserver.go
updateServices
func (v *vserver) updateServices(ip seesaw.IP) { for _, s := range v.services { if !s.ip.Equal(ip) { continue } if !v.active[ip] { if s.active { s.down() } continue } switch { case !s.healthy && s.active: s.down() case s.healthy && !s.active: s.up() } } }
go
func (v *vserver) updateServices(ip seesaw.IP) { for _, s := range v.services { if !s.ip.Equal(ip) { continue } if !v.active[ip] { if s.active { s.down() } continue } switch { case !s.healthy && s.active: s.down() case s.healthy && !s.active: s.up() } } }
[ "func", "(", "v", "*", "vserver", ")", "updateServices", "(", "ip", "seesaw", ".", "IP", ")", "{", "for", "_", ",", "s", ":=", "range", "v", ".", "services", "{", "if", "!", "s", ".", "ip", ".", "Equal", "(", "ip", ")", "{", "continue", "\n", "}", "\n", "if", "!", "v", ".", "active", "[", "ip", "]", "{", "if", "s", ".", "active", "{", "s", ".", "down", "(", ")", "\n", "}", "\n", "continue", "\n", "}", "\n", "switch", "{", "case", "!", "s", ".", "healthy", "&&", "s", ".", "active", ":", "s", ".", "down", "(", ")", "\n", "case", "s", ".", "healthy", "&&", "!", "s", ".", "active", ":", "s", ".", "up", "(", ")", "\n", "}", "\n", "}", "\n", "}" ]
// updateServices brings the services for a vserver up or down based on the // state of the vserver and the health of each service.
[ "updateServices", "brings", "the", "services", "for", "a", "vserver", "up", "or", "down", "based", "on", "the", "state", "of", "the", "vserver", "and", "the", "health", "of", "each", "service", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/vserver.go#L1211-L1229
train
google/seesaw
engine/vserver.go
up
func (v *vserver) up(ip seesaw.IP) { ncc := v.engine.ncc if err := ncc.Dial(); err != nil { log.Fatalf("%v: failed to connect to NCC: %v", v, err) } defer ncc.Close() v.active[ip] = true v.updateServices(ip) // If this is an anycast VIP, start advertising a BGP route. nip := ip.IP() if seesaw.IsAnycast(nip) { // TODO(jsing): Create an LBVserver that only encapsulates // the necessary state, rather than storing a full vserver // snapshot. lbVserver := v.snapshot() lbVserver.Services = nil lbVserver.Warnings = nil if err := v.engine.lbInterface.AddVserver(lbVserver, ip.AF()); err != nil { log.Fatalf("%v: failed to add Vserver: %v", v, err) } v.lbVservers[ip] = lbVserver vip := seesaw.NewVIP(nip, nil) if err := v.engine.lbInterface.AddVIP(vip); err != nil { log.Fatalf("%v: failed to add VIP %v: %v", v, ip, err) } // TODO(angusc): Filter out anycast VIPs for non-anycast clusters further // upstream. if v.engine.config.AnycastEnabled { log.Infof("%v: advertising BGP route for %v", v, ip) if err := ncc.BGPAdvertiseVIP(nip); err != nil { log.Fatalf("%v: failed to advertise VIP %v: %v", v, ip, err) } } else { log.Warningf("%v: %v is an anycast VIP, but anycast is not enabled", v, ip) } } log.Infof("%v: VIP %v up", v, ip) }
go
func (v *vserver) up(ip seesaw.IP) { ncc := v.engine.ncc if err := ncc.Dial(); err != nil { log.Fatalf("%v: failed to connect to NCC: %v", v, err) } defer ncc.Close() v.active[ip] = true v.updateServices(ip) // If this is an anycast VIP, start advertising a BGP route. nip := ip.IP() if seesaw.IsAnycast(nip) { // TODO(jsing): Create an LBVserver that only encapsulates // the necessary state, rather than storing a full vserver // snapshot. lbVserver := v.snapshot() lbVserver.Services = nil lbVserver.Warnings = nil if err := v.engine.lbInterface.AddVserver(lbVserver, ip.AF()); err != nil { log.Fatalf("%v: failed to add Vserver: %v", v, err) } v.lbVservers[ip] = lbVserver vip := seesaw.NewVIP(nip, nil) if err := v.engine.lbInterface.AddVIP(vip); err != nil { log.Fatalf("%v: failed to add VIP %v: %v", v, ip, err) } // TODO(angusc): Filter out anycast VIPs for non-anycast clusters further // upstream. if v.engine.config.AnycastEnabled { log.Infof("%v: advertising BGP route for %v", v, ip) if err := ncc.BGPAdvertiseVIP(nip); err != nil { log.Fatalf("%v: failed to advertise VIP %v: %v", v, ip, err) } } else { log.Warningf("%v: %v is an anycast VIP, but anycast is not enabled", v, ip) } } log.Infof("%v: VIP %v up", v, ip) }
[ "func", "(", "v", "*", "vserver", ")", "up", "(", "ip", "seesaw", ".", "IP", ")", "{", "ncc", ":=", "v", ".", "engine", ".", "ncc", "\n", "if", "err", ":=", "ncc", ".", "Dial", "(", ")", ";", "err", "!=", "nil", "{", "log", ".", "Fatalf", "(", "\"%v: failed to connect to NCC: %v\"", ",", "v", ",", "err", ")", "\n", "}", "\n", "defer", "ncc", ".", "Close", "(", ")", "\n", "v", ".", "active", "[", "ip", "]", "=", "true", "\n", "v", ".", "updateServices", "(", "ip", ")", "\n", "nip", ":=", "ip", ".", "IP", "(", ")", "\n", "if", "seesaw", ".", "IsAnycast", "(", "nip", ")", "{", "lbVserver", ":=", "v", ".", "snapshot", "(", ")", "\n", "lbVserver", ".", "Services", "=", "nil", "\n", "lbVserver", ".", "Warnings", "=", "nil", "\n", "if", "err", ":=", "v", ".", "engine", ".", "lbInterface", ".", "AddVserver", "(", "lbVserver", ",", "ip", ".", "AF", "(", ")", ")", ";", "err", "!=", "nil", "{", "log", ".", "Fatalf", "(", "\"%v: failed to add Vserver: %v\"", ",", "v", ",", "err", ")", "\n", "}", "\n", "v", ".", "lbVservers", "[", "ip", "]", "=", "lbVserver", "\n", "vip", ":=", "seesaw", ".", "NewVIP", "(", "nip", ",", "nil", ")", "\n", "if", "err", ":=", "v", ".", "engine", ".", "lbInterface", ".", "AddVIP", "(", "vip", ")", ";", "err", "!=", "nil", "{", "log", ".", "Fatalf", "(", "\"%v: failed to add VIP %v: %v\"", ",", "v", ",", "ip", ",", "err", ")", "\n", "}", "\n", "if", "v", ".", "engine", ".", "config", ".", "AnycastEnabled", "{", "log", ".", "Infof", "(", "\"%v: advertising BGP route for %v\"", ",", "v", ",", "ip", ")", "\n", "if", "err", ":=", "ncc", ".", "BGPAdvertiseVIP", "(", "nip", ")", ";", "err", "!=", "nil", "{", "log", ".", "Fatalf", "(", "\"%v: failed to advertise VIP %v: %v\"", ",", "v", ",", "ip", ",", "err", ")", "\n", "}", "\n", "}", "else", "{", "log", ".", "Warningf", "(", "\"%v: %v is an anycast VIP, but anycast is not enabled\"", ",", "v", ",", "ip", ")", "\n", "}", "\n", "}", "\n", "log", ".", "Infof", "(", "\"%v: VIP %v up\"", ",", "v", ",", "ip", ")", "\n", "}" ]
// up brings up all healthy services for an IP address for a vserver, then // brings up the IP address.
[ "up", "brings", "up", "all", "healthy", "services", "for", "an", "IP", "address", "for", "a", "vserver", "then", "brings", "up", "the", "IP", "address", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/vserver.go#L1233-L1274
train
google/seesaw
engine/vserver.go
downAll
func (v *vserver) downAll() { for _, s := range v.services { if v.active[s.ip] { v.down(s.ip) } if s.active { s.down() } } }
go
func (v *vserver) downAll() { for _, s := range v.services { if v.active[s.ip] { v.down(s.ip) } if s.active { s.down() } } }
[ "func", "(", "v", "*", "vserver", ")", "downAll", "(", ")", "{", "for", "_", ",", "s", ":=", "range", "v", ".", "services", "{", "if", "v", ".", "active", "[", "s", ".", "ip", "]", "{", "v", ".", "down", "(", "s", ".", "ip", ")", "\n", "}", "\n", "if", "s", ".", "active", "{", "s", ".", "down", "(", ")", "\n", "}", "\n", "}", "\n", "}" ]
// downAll takes down all IP addresses and services for a vserver.
[ "downAll", "takes", "down", "all", "IP", "addresses", "and", "services", "for", "a", "vserver", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/vserver.go#L1277-L1286
train
google/seesaw
engine/vserver.go
down
func (v *vserver) down(ip seesaw.IP) { ncc := v.engine.ncc if err := ncc.Dial(); err != nil { log.Fatalf("%v: failed to connect to NCC: %v", v, err) } defer ncc.Close() // If this is an anycast VIP, withdraw the BGP route. nip := ip.IP() if seesaw.IsAnycast(nip) { if v.engine.config.AnycastEnabled { log.Infof("%v: withdrawing BGP route for %v", v, ip) if err := ncc.BGPWithdrawVIP(nip); err != nil { log.Fatalf("%v: failed to withdraw VIP %v: %v", v, ip, err) } } vip := seesaw.NewVIP(nip, nil) if err := v.engine.lbInterface.DeleteVIP(vip); err != nil { log.Fatalf("%v: failed to remove VIP %v: %v", v, ip, err) } if err := v.engine.lbInterface.DeleteVserver(v.lbVservers[ip], ip.AF()); err != nil { log.Fatalf("%v: failed to delete Vserver: %v", v, err) } delete(v.lbVservers, ip) } // TODO(jsing): Should we delay while the BGP routes propagate? delete(v.active, ip) v.updateServices(ip) log.Infof("%v: VIP %v down", v, ip) }
go
func (v *vserver) down(ip seesaw.IP) { ncc := v.engine.ncc if err := ncc.Dial(); err != nil { log.Fatalf("%v: failed to connect to NCC: %v", v, err) } defer ncc.Close() // If this is an anycast VIP, withdraw the BGP route. nip := ip.IP() if seesaw.IsAnycast(nip) { if v.engine.config.AnycastEnabled { log.Infof("%v: withdrawing BGP route for %v", v, ip) if err := ncc.BGPWithdrawVIP(nip); err != nil { log.Fatalf("%v: failed to withdraw VIP %v: %v", v, ip, err) } } vip := seesaw.NewVIP(nip, nil) if err := v.engine.lbInterface.DeleteVIP(vip); err != nil { log.Fatalf("%v: failed to remove VIP %v: %v", v, ip, err) } if err := v.engine.lbInterface.DeleteVserver(v.lbVservers[ip], ip.AF()); err != nil { log.Fatalf("%v: failed to delete Vserver: %v", v, err) } delete(v.lbVservers, ip) } // TODO(jsing): Should we delay while the BGP routes propagate? delete(v.active, ip) v.updateServices(ip) log.Infof("%v: VIP %v down", v, ip) }
[ "func", "(", "v", "*", "vserver", ")", "down", "(", "ip", "seesaw", ".", "IP", ")", "{", "ncc", ":=", "v", ".", "engine", ".", "ncc", "\n", "if", "err", ":=", "ncc", ".", "Dial", "(", ")", ";", "err", "!=", "nil", "{", "log", ".", "Fatalf", "(", "\"%v: failed to connect to NCC: %v\"", ",", "v", ",", "err", ")", "\n", "}", "\n", "defer", "ncc", ".", "Close", "(", ")", "\n", "nip", ":=", "ip", ".", "IP", "(", ")", "\n", "if", "seesaw", ".", "IsAnycast", "(", "nip", ")", "{", "if", "v", ".", "engine", ".", "config", ".", "AnycastEnabled", "{", "log", ".", "Infof", "(", "\"%v: withdrawing BGP route for %v\"", ",", "v", ",", "ip", ")", "\n", "if", "err", ":=", "ncc", ".", "BGPWithdrawVIP", "(", "nip", ")", ";", "err", "!=", "nil", "{", "log", ".", "Fatalf", "(", "\"%v: failed to withdraw VIP %v: %v\"", ",", "v", ",", "ip", ",", "err", ")", "\n", "}", "\n", "}", "\n", "vip", ":=", "seesaw", ".", "NewVIP", "(", "nip", ",", "nil", ")", "\n", "if", "err", ":=", "v", ".", "engine", ".", "lbInterface", ".", "DeleteVIP", "(", "vip", ")", ";", "err", "!=", "nil", "{", "log", ".", "Fatalf", "(", "\"%v: failed to remove VIP %v: %v\"", ",", "v", ",", "ip", ",", "err", ")", "\n", "}", "\n", "if", "err", ":=", "v", ".", "engine", ".", "lbInterface", ".", "DeleteVserver", "(", "v", ".", "lbVservers", "[", "ip", "]", ",", "ip", ".", "AF", "(", ")", ")", ";", "err", "!=", "nil", "{", "log", ".", "Fatalf", "(", "\"%v: failed to delete Vserver: %v\"", ",", "v", ",", "err", ")", "\n", "}", "\n", "delete", "(", "v", ".", "lbVservers", ",", "ip", ")", "\n", "}", "\n", "delete", "(", "v", ".", "active", ",", "ip", ")", "\n", "v", ".", "updateServices", "(", "ip", ")", "\n", "log", ".", "Infof", "(", "\"%v: VIP %v down\"", ",", "v", ",", "ip", ")", "\n", "}" ]
// down takes down an IP address for a vserver, then takes down all services // for that IP address.
[ "down", "takes", "down", "an", "IP", "address", "for", "a", "vserver", "then", "takes", "down", "all", "services", "for", "that", "IP", "address", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/vserver.go#L1290-L1320
train
google/seesaw
engine/vserver.go
configureVIPs
func (v *vserver) configureVIPs() { ncc := v.engine.ncc if err := ncc.Dial(); err != nil { log.Fatalf("%v: failed to connect to NCC: %v", v, err) } defer ncc.Close() // TODO(ncope): Return to iterating over v.services once they contain seesaw.VIPs. for _, vip := range v.config.VIPs { if _, ok := v.vips[*vip]; ok { continue } // TODO(angusc): Set up anycast Vservers here as well (without bringing up the VIP). if vip.Type == seesaw.AnycastVIP { continue } // TODO(jsing): Create a ncc.LBVserver that only encapsulates // the necessary state, rather than storing a full vserver // snapshot. lbVserver := v.snapshot() lbVserver.Services = nil lbVserver.Warnings = nil if err := v.engine.lbInterface.AddVserver(lbVserver, vip.IP.AF()); err != nil { log.Fatalf("%v: failed to add Vserver: %v", v, err) } v.lbVservers[vip.IP] = lbVserver if err := v.engine.lbInterface.AddVIP(vip); err != nil { log.Fatalf("%v: failed to add VIP %v: %v", v, vip.IP, err) } v.vips[*vip] = true } }
go
func (v *vserver) configureVIPs() { ncc := v.engine.ncc if err := ncc.Dial(); err != nil { log.Fatalf("%v: failed to connect to NCC: %v", v, err) } defer ncc.Close() // TODO(ncope): Return to iterating over v.services once they contain seesaw.VIPs. for _, vip := range v.config.VIPs { if _, ok := v.vips[*vip]; ok { continue } // TODO(angusc): Set up anycast Vservers here as well (without bringing up the VIP). if vip.Type == seesaw.AnycastVIP { continue } // TODO(jsing): Create a ncc.LBVserver that only encapsulates // the necessary state, rather than storing a full vserver // snapshot. lbVserver := v.snapshot() lbVserver.Services = nil lbVserver.Warnings = nil if err := v.engine.lbInterface.AddVserver(lbVserver, vip.IP.AF()); err != nil { log.Fatalf("%v: failed to add Vserver: %v", v, err) } v.lbVservers[vip.IP] = lbVserver if err := v.engine.lbInterface.AddVIP(vip); err != nil { log.Fatalf("%v: failed to add VIP %v: %v", v, vip.IP, err) } v.vips[*vip] = true } }
[ "func", "(", "v", "*", "vserver", ")", "configureVIPs", "(", ")", "{", "ncc", ":=", "v", ".", "engine", ".", "ncc", "\n", "if", "err", ":=", "ncc", ".", "Dial", "(", ")", ";", "err", "!=", "nil", "{", "log", ".", "Fatalf", "(", "\"%v: failed to connect to NCC: %v\"", ",", "v", ",", "err", ")", "\n", "}", "\n", "defer", "ncc", ".", "Close", "(", ")", "\n", "for", "_", ",", "vip", ":=", "range", "v", ".", "config", ".", "VIPs", "{", "if", "_", ",", "ok", ":=", "v", ".", "vips", "[", "*", "vip", "]", ";", "ok", "{", "continue", "\n", "}", "\n", "if", "vip", ".", "Type", "==", "seesaw", ".", "AnycastVIP", "{", "continue", "\n", "}", "\n", "lbVserver", ":=", "v", ".", "snapshot", "(", ")", "\n", "lbVserver", ".", "Services", "=", "nil", "\n", "lbVserver", ".", "Warnings", "=", "nil", "\n", "if", "err", ":=", "v", ".", "engine", ".", "lbInterface", ".", "AddVserver", "(", "lbVserver", ",", "vip", ".", "IP", ".", "AF", "(", ")", ")", ";", "err", "!=", "nil", "{", "log", ".", "Fatalf", "(", "\"%v: failed to add Vserver: %v\"", ",", "v", ",", "err", ")", "\n", "}", "\n", "v", ".", "lbVservers", "[", "vip", ".", "IP", "]", "=", "lbVserver", "\n", "if", "err", ":=", "v", ".", "engine", ".", "lbInterface", ".", "AddVIP", "(", "vip", ")", ";", "err", "!=", "nil", "{", "log", ".", "Fatalf", "(", "\"%v: failed to add VIP %v: %v\"", ",", "v", ",", "vip", ".", "IP", ",", "err", ")", "\n", "}", "\n", "v", ".", "vips", "[", "*", "vip", "]", "=", "true", "\n", "}", "\n", "}" ]
// configureVIPs configures VIPs on the load balancing interface.
[ "configureVIPs", "configures", "VIPs", "on", "the", "load", "balancing", "interface", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/vserver.go#L1330-L1363
train
google/seesaw
engine/vserver.go
unconfigureVIP
func (v *vserver) unconfigureVIP(vip *seesaw.VIP) { configured, ok := v.vips[*vip] if !ok { return } if configured { ncc := v.engine.ncc if err := ncc.Dial(); err != nil { log.Fatalf("%v: failed to connect to NCC: %v", v, err) } defer ncc.Close() if err := v.engine.lbInterface.DeleteVIP(vip); err != nil { log.Fatalf("%v: failed to remove VIP %v: %v", v, vip, err) } if err := v.engine.lbInterface.DeleteVserver(v.lbVservers[vip.IP], vip.IP.AF()); err != nil { log.Fatalf("%v: failed to delete Vserver: %v", v, err) } delete(v.lbVservers, vip.IP) } delete(v.vips, *vip) }
go
func (v *vserver) unconfigureVIP(vip *seesaw.VIP) { configured, ok := v.vips[*vip] if !ok { return } if configured { ncc := v.engine.ncc if err := ncc.Dial(); err != nil { log.Fatalf("%v: failed to connect to NCC: %v", v, err) } defer ncc.Close() if err := v.engine.lbInterface.DeleteVIP(vip); err != nil { log.Fatalf("%v: failed to remove VIP %v: %v", v, vip, err) } if err := v.engine.lbInterface.DeleteVserver(v.lbVservers[vip.IP], vip.IP.AF()); err != nil { log.Fatalf("%v: failed to delete Vserver: %v", v, err) } delete(v.lbVservers, vip.IP) } delete(v.vips, *vip) }
[ "func", "(", "v", "*", "vserver", ")", "unconfigureVIP", "(", "vip", "*", "seesaw", ".", "VIP", ")", "{", "configured", ",", "ok", ":=", "v", ".", "vips", "[", "*", "vip", "]", "\n", "if", "!", "ok", "{", "return", "\n", "}", "\n", "if", "configured", "{", "ncc", ":=", "v", ".", "engine", ".", "ncc", "\n", "if", "err", ":=", "ncc", ".", "Dial", "(", ")", ";", "err", "!=", "nil", "{", "log", ".", "Fatalf", "(", "\"%v: failed to connect to NCC: %v\"", ",", "v", ",", "err", ")", "\n", "}", "\n", "defer", "ncc", ".", "Close", "(", ")", "\n", "if", "err", ":=", "v", ".", "engine", ".", "lbInterface", ".", "DeleteVIP", "(", "vip", ")", ";", "err", "!=", "nil", "{", "log", ".", "Fatalf", "(", "\"%v: failed to remove VIP %v: %v\"", ",", "v", ",", "vip", ",", "err", ")", "\n", "}", "\n", "if", "err", ":=", "v", ".", "engine", ".", "lbInterface", ".", "DeleteVserver", "(", "v", ".", "lbVservers", "[", "vip", ".", "IP", "]", ",", "vip", ".", "IP", ".", "AF", "(", ")", ")", ";", "err", "!=", "nil", "{", "log", ".", "Fatalf", "(", "\"%v: failed to delete Vserver: %v\"", ",", "v", ",", "err", ")", "\n", "}", "\n", "delete", "(", "v", ".", "lbVservers", ",", "vip", ".", "IP", ")", "\n", "}", "\n", "delete", "(", "v", ".", "vips", ",", "*", "vip", ")", "\n", "}" ]
// unconfigureVIP removes a unicast VIP from the load balancing interface.
[ "unconfigureVIP", "removes", "a", "unicast", "VIP", "from", "the", "load", "balancing", "interface", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/vserver.go#L1366-L1387
train
google/seesaw
engine/vserver.go
unconfigureVIPs
func (v *vserver) unconfigureVIPs() { ncc := v.engine.ncc if err := ncc.Dial(); err != nil { log.Fatalf("%v: failed to connect to NCC: %v", v, err) } defer ncc.Close() // TODO(jsing): At a later date this will need to support VLAN // interfaces and dedicated VIP subnets. for vip := range v.vips { v.unconfigureVIP(&vip) } }
go
func (v *vserver) unconfigureVIPs() { ncc := v.engine.ncc if err := ncc.Dial(); err != nil { log.Fatalf("%v: failed to connect to NCC: %v", v, err) } defer ncc.Close() // TODO(jsing): At a later date this will need to support VLAN // interfaces and dedicated VIP subnets. for vip := range v.vips { v.unconfigureVIP(&vip) } }
[ "func", "(", "v", "*", "vserver", ")", "unconfigureVIPs", "(", ")", "{", "ncc", ":=", "v", ".", "engine", ".", "ncc", "\n", "if", "err", ":=", "ncc", ".", "Dial", "(", ")", ";", "err", "!=", "nil", "{", "log", ".", "Fatalf", "(", "\"%v: failed to connect to NCC: %v\"", ",", "v", ",", "err", ")", "\n", "}", "\n", "defer", "ncc", ".", "Close", "(", ")", "\n", "for", "vip", ":=", "range", "v", ".", "vips", "{", "v", ".", "unconfigureVIP", "(", "&", "vip", ")", "\n", "}", "\n", "}" ]
// unconfigureVIPs removes unicast VIPs from the load balancing interface.
[ "unconfigureVIPs", "removes", "unicast", "VIPs", "from", "the", "load", "balancing", "interface", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/vserver.go#L1390-L1402
train
google/seesaw
engine/config/fetcher.go
fetchFromHost
func (f *fetcher) fetchFromHost(ip net.IP, url, contentType string) ([]byte, error) { // TODO(angusc): connection timeout? tcpAddr := &net.TCPAddr{IP: ip, Port: f.port} tcpConn, err := net.DialTCP("tcp", nil, tcpAddr) if err != nil { return nil, err } defer tcpConn.Close() tcpConn.SetDeadline(time.Now().Add(f.timeout)) dialer := func(net string, addr string) (net.Conn, error) { return tcpConn, nil } client := &http.Client{ CheckRedirect: func(req *http.Request, via []*http.Request) error { return errors.New("HTTP redirect prohibited") }, Transport: &http.Transport{ Dial: dialer, DisableKeepAlives: true, TLSClientConfig: &tls.Config{ RootCAs: f.certs, }, }, } req, err := http.NewRequest("GET", url, nil) if err != nil { return nil, err } req.Header.Add("Connection", "close") resp, err := client.Do(req) if err != nil { return nil, err } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("received HTTP status %s", resp.Status) } if ct := resp.Header.Get("Content-Type"); ct != contentType { return nil, fmt.Errorf("unexpected Content-Type: %q", ct) } return ioutil.ReadAll(resp.Body) }
go
func (f *fetcher) fetchFromHost(ip net.IP, url, contentType string) ([]byte, error) { // TODO(angusc): connection timeout? tcpAddr := &net.TCPAddr{IP: ip, Port: f.port} tcpConn, err := net.DialTCP("tcp", nil, tcpAddr) if err != nil { return nil, err } defer tcpConn.Close() tcpConn.SetDeadline(time.Now().Add(f.timeout)) dialer := func(net string, addr string) (net.Conn, error) { return tcpConn, nil } client := &http.Client{ CheckRedirect: func(req *http.Request, via []*http.Request) error { return errors.New("HTTP redirect prohibited") }, Transport: &http.Transport{ Dial: dialer, DisableKeepAlives: true, TLSClientConfig: &tls.Config{ RootCAs: f.certs, }, }, } req, err := http.NewRequest("GET", url, nil) if err != nil { return nil, err } req.Header.Add("Connection", "close") resp, err := client.Do(req) if err != nil { return nil, err } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("received HTTP status %s", resp.Status) } if ct := resp.Header.Get("Content-Type"); ct != contentType { return nil, fmt.Errorf("unexpected Content-Type: %q", ct) } return ioutil.ReadAll(resp.Body) }
[ "func", "(", "f", "*", "fetcher", ")", "fetchFromHost", "(", "ip", "net", ".", "IP", ",", "url", ",", "contentType", "string", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "tcpAddr", ":=", "&", "net", ".", "TCPAddr", "{", "IP", ":", "ip", ",", "Port", ":", "f", ".", "port", "}", "\n", "tcpConn", ",", "err", ":=", "net", ".", "DialTCP", "(", "\"tcp\"", ",", "nil", ",", "tcpAddr", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "defer", "tcpConn", ".", "Close", "(", ")", "\n", "tcpConn", ".", "SetDeadline", "(", "time", ".", "Now", "(", ")", ".", "Add", "(", "f", ".", "timeout", ")", ")", "\n", "dialer", ":=", "func", "(", "net", "string", ",", "addr", "string", ")", "(", "net", ".", "Conn", ",", "error", ")", "{", "return", "tcpConn", ",", "nil", "\n", "}", "\n", "client", ":=", "&", "http", ".", "Client", "{", "CheckRedirect", ":", "func", "(", "req", "*", "http", ".", "Request", ",", "via", "[", "]", "*", "http", ".", "Request", ")", "error", "{", "return", "errors", ".", "New", "(", "\"HTTP redirect prohibited\"", ")", "\n", "}", ",", "Transport", ":", "&", "http", ".", "Transport", "{", "Dial", ":", "dialer", ",", "DisableKeepAlives", ":", "true", ",", "TLSClientConfig", ":", "&", "tls", ".", "Config", "{", "RootCAs", ":", "f", ".", "certs", ",", "}", ",", "}", ",", "}", "\n", "req", ",", "err", ":=", "http", ".", "NewRequest", "(", "\"GET\"", ",", "url", ",", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "req", ".", "Header", ".", "Add", "(", "\"Connection\"", ",", "\"close\"", ")", "\n", "resp", ",", "err", ":=", "client", ".", "Do", "(", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "defer", "resp", ".", "Body", ".", "Close", "(", ")", "\n", "if", "resp", ".", "StatusCode", "!=", "http", ".", "StatusOK", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"received HTTP status %s\"", ",", "resp", ".", "Status", ")", "\n", "}", "\n", "if", "ct", ":=", "resp", ".", "Header", ".", "Get", "(", "\"Content-Type\"", ")", ";", "ct", "!=", "contentType", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"unexpected Content-Type: %q\"", ",", "ct", ")", "\n", "}", "\n", "return", "ioutil", ".", "ReadAll", "(", "resp", ".", "Body", ")", "\n", "}" ]
// fetchFromHost attempts to fetch the specified URL from a specific host.
[ "fetchFromHost", "attempts", "to", "fetch", "the", "specified", "URL", "from", "a", "specific", "host", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/config/fetcher.go#L86-L130
train
google/seesaw
netlink/netlink.go
uint16FromNetwork
func uint16FromNetwork(u uint16) uint16 { b := *(*[2]byte)(unsafe.Pointer(&u)) return binary.BigEndian.Uint16(b[:]) }
go
func uint16FromNetwork(u uint16) uint16 { b := *(*[2]byte)(unsafe.Pointer(&u)) return binary.BigEndian.Uint16(b[:]) }
[ "func", "uint16FromNetwork", "(", "u", "uint16", ")", "uint16", "{", "b", ":=", "*", "(", "*", "[", "2", "]", "byte", ")", "(", "unsafe", ".", "Pointer", "(", "&", "u", ")", ")", "\n", "return", "binary", ".", "BigEndian", ".", "Uint16", "(", "b", "[", ":", "]", ")", "\n", "}" ]
// uint16FromNetwork converts the given value from its network byte order.
[ "uint16FromNetwork", "converts", "the", "given", "value", "from", "its", "network", "byte", "order", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/netlink/netlink.go#L48-L51
train
google/seesaw
netlink/netlink.go
uint16ToNetwork
func uint16ToNetwork(u uint16) uint16 { var b [2]byte binary.BigEndian.PutUint16(b[:], u) return *(*uint16)(unsafe.Pointer(&b)) }
go
func uint16ToNetwork(u uint16) uint16 { var b [2]byte binary.BigEndian.PutUint16(b[:], u) return *(*uint16)(unsafe.Pointer(&b)) }
[ "func", "uint16ToNetwork", "(", "u", "uint16", ")", "uint16", "{", "var", "b", "[", "2", "]", "byte", "\n", "binary", ".", "BigEndian", ".", "PutUint16", "(", "b", "[", ":", "]", ",", "u", ")", "\n", "return", "*", "(", "*", "uint16", ")", "(", "unsafe", ".", "Pointer", "(", "&", "b", ")", ")", "\n", "}" ]
// uint16ToNetwork converts the given value to its network byte order.
[ "uint16ToNetwork", "converts", "the", "given", "value", "to", "its", "network", "byte", "order", "." ]
34716af0775ecb1fad239a726390d63d6b0742dd
https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/netlink/netlink.go#L54-L58
train