repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
sequence | docstring
stringlengths 6
2.61k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 85
252
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
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",
"(",
"\"",
"\"",
")",
"\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",
"(",
"\"",
"\"",
",",
"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\n",
"s",
".",
"server",
"=",
"rpc",
".",
"NewServer",
"(",
")",
"\n",
"s",
".",
"server",
".",
"Register",
"(",
"&",
"SeesawSync",
"{",
"s",
"}",
")",
"\n\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",
"(",
"\"",
"\"",
",",
"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",
"(",
"\"",
"\"",
",",
"rip",
")",
"\n",
"c",
".",
"Close",
"(",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"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",
"(",
"\"",
"\"",
",",
"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\n",
"// TODO(jsing): Make this default to IPv6, if configured.",
"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",
"(",
"\"",
"\"",
",",
"self",
",",
"peer",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"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",
"(",
"\"",
"\"",
",",
"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",
"(",
"\"",
"\"",
",",
"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",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n",
"defer",
"sc",
".",
"close",
"(",
")",
"\n\n",
"var",
"sid",
"SyncSessionID",
"\n",
"self",
":=",
"sc",
".",
"engine",
".",
"config",
".",
"Node",
".",
"IPv4Addr",
"\n\n",
"// Register for synchronisation events.",
"// TODO(jsing): Implement timeout on RPC?",
"if",
"err",
":=",
"sc",
".",
"client",
".",
"Call",
"(",
"\"",
"\"",
",",
"self",
",",
"&",
"sid",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Warningf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"sid",
")",
"\n\n",
"// TODO(jsing): Export synchronisation data to ECU/CLI.",
"sc",
".",
"poll",
"(",
"sid",
")",
"\n\n",
"// Attempt to deregister for notifications.",
"// TODO(jsing): Implement timeout on RPC?",
"if",
"err",
":=",
"sc",
".",
"client",
".",
"Call",
"(",
"\"",
"\"",
",",
"sid",
",",
"nil",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Warningf",
"(",
"\"",
"\"",
",",
"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(¬e)
}
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(¬e)
}
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",
"(",
"\"",
"\"",
",",
"sid",
",",
"&",
"sn",
",",
"nil",
")",
"\n",
"select",
"{",
"case",
"<-",
"poll",
".",
"Done",
":",
"if",
"poll",
".",
"Error",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"poll",
".",
"Error",
")",
"\n",
"return",
"\n",
"}",
"\n",
"for",
"_",
",",
"note",
":=",
"range",
"sn",
".",
"Notes",
"{",
"sc",
".",
"dispatch",
"(",
"&",
"note",
")",
"\n",
"}",
"\n\n",
"case",
"<-",
"sc",
".",
"quit",
":",
"sc",
".",
"stopped",
"<-",
"true",
"\n",
"return",
"\n\n",
"case",
"<-",
"time",
".",
"After",
"(",
"syncPollTimeout",
")",
":",
"log",
".",
"Warningf",
"(",
"\"",
"\"",
",",
"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",
"(",
"\"",
"\"",
")",
"\n\n",
"case",
"SNTDesync",
":",
"sc",
".",
"handleDesync",
"(",
")",
"\n\n",
"case",
"SNTConfigUpdate",
":",
"sc",
".",
"handleConfigUpdate",
"(",
"note",
")",
"\n\n",
"case",
"SNTHealthcheck",
":",
"sc",
".",
"handleHealthcheck",
"(",
"note",
")",
"\n\n",
"case",
"SNTOverride",
":",
"sc",
".",
"handleOverride",
"(",
"note",
")",
"\n\n",
"default",
":",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"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",
"(",
"\"",
"\"",
")",
"\n\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",
"(",
"\"",
"\"",
")",
"\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",
"\"",
"\"",
"\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",
"\"",
"\"",
"\n",
"case",
"HCTypeHTTP",
":",
"return",
"\"",
"\"",
"\n",
"// TODO(angusc): Drop HTTPS as a separate type.",
"case",
"HCTypeHTTPS",
":",
"return",
"\"",
"\"",
"// NB: Not HTTPS",
"\n",
"case",
"HCTypeICMP",
":",
"return",
"\"",
"\"",
"\n",
"case",
"HCTypeRADIUS",
":",
"return",
"\"",
"\"",
"\n",
"case",
"HCTypeTCP",
":",
"return",
"\"",
"\"",
"\n",
"// TODO(angusc): Drop TCPTLS as a separate type.",
"case",
"HCTypeTCPTLS",
":",
"return",
"\"",
"\"",
"// NB: Not TCPTLS",
"\n",
"case",
"HCTypeUDP",
":",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
"\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",
".",
"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",
"\"",
"\"",
"\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",
"\"",
"\"",
"\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",
"(",
"\"",
"\"",
",",
"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",
"(",
"\"",
"\"",
",",
"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",
"(",
"\"",
"\"",
",",
"*",
"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",
"(",
"\"",
"\"",
",",
"s",
".",
"ip",
",",
"s",
".",
"fwm",
")",
"\n",
"}",
"\n",
"ip",
":=",
"s",
".",
"ip",
".",
"String",
"(",
")",
"\n",
"port",
":=",
"strconv",
".",
"Itoa",
"(",
"int",
"(",
"s",
".",
"port",
")",
")",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"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",
"(",
"\"",
"\"",
",",
"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",
"(",
"\"",
"\"",
",",
"d",
".",
"ip",
")",
"\n",
"}",
"\n",
"ip",
":=",
"d",
".",
"ip",
".",
"String",
"(",
")",
"\n",
"port",
":=",
"strconv",
".",
"Itoa",
"(",
"int",
"(",
"d",
".",
"service",
".",
"port",
")",
")",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"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",
"(",
"\"",
"\"",
",",
"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",
"(",
"\"",
"\"",
",",
"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\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\n",
"// 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",
"\n",
"for",
"_",
",",
"entry",
":=",
"range",
"v",
".",
"config",
".",
"Entries",
"{",
"ventry",
"=",
"entry",
"\n",
"break",
"\n",
"}",
"\n\n",
"if",
"v",
".",
"fwm",
"[",
"af",
"]",
"==",
"0",
"{",
"mark",
",",
"err",
":=",
"v",
".",
"engine",
".",
"fwmAlloc",
".",
"get",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"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",
"{",
"// vserver-level 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\n",
"// 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",
")",
"\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",
":",
"// 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",
"(",
")",
"\n",
"statsTicker",
".",
"Stop",
"(",
")",
"\n",
"v",
".",
"engine",
".",
"hcManager",
".",
"vcc",
"<-",
"vserverChecks",
"{",
"vserverName",
":",
"v",
".",
"config",
".",
"Name",
"}",
"\n",
"v",
".",
"unconfigureVIPs",
"(",
")",
"\n\n",
"// Return any firewall marks that were allocated to",
"// this vserver.",
"for",
"_",
",",
"fwm",
":=",
"range",
"v",
".",
"fwm",
"{",
"v",
".",
"engine",
".",
"fwmAlloc",
".",
"put",
"(",
"fwm",
")",
"\n",
"}",
"\n\n",
"v",
".",
"stopped",
"<-",
"true",
"\n",
"return",
"\n\n",
"case",
"o",
":=",
"<-",
"v",
".",
"overrideChan",
":",
"v",
".",
"handleOverride",
"(",
"o",
")",
"\n",
"v",
".",
"engine",
".",
"hcManager",
".",
"vcc",
"<-",
"v",
".",
"healthchecks",
"(",
")",
"\n\n",
"case",
"config",
":=",
"<-",
"v",
".",
"update",
":",
"v",
".",
"handleConfigUpdate",
"(",
"config",
")",
"\n",
"v",
".",
"engine",
".",
"hcManager",
".",
"vcc",
"<-",
"v",
".",
"healthchecks",
"(",
")",
"\n\n",
"case",
"n",
":=",
"<-",
"v",
".",
"notify",
":",
"v",
".",
"handleCheckNotification",
"(",
"n",
")",
"\n\n",
"case",
"<-",
"statsTicker",
".",
"C",
":",
"v",
".",
"updateStats",
"(",
")",
"\n",
"}",
"\n\n",
"// 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",
")",
"\n",
"select",
"{",
"case",
"v",
".",
"engine",
".",
"vserverChan",
"<-",
"v",
".",
"snapshot",
"(",
")",
":",
"case",
"<-",
"timeout",
":",
"log",
".",
"Warningf",
"(",
"\"",
"\"",
",",
"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\n",
"case",
"v",
".",
"enabled",
"&&",
"!",
"vserverEnabled",
"(",
"config",
",",
"v",
".",
"vserverOverride",
".",
"State",
"(",
")",
")",
":",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"v",
")",
"\n",
"v",
".",
"downAll",
"(",
")",
"\n",
"v",
".",
"unconfigureVIPs",
"(",
")",
"\n",
"v",
".",
"configInit",
"(",
"config",
")",
"\n",
"return",
"\n\n",
"case",
"!",
"v",
".",
"enabled",
"&&",
"!",
"vserverEnabled",
"(",
"config",
",",
"v",
".",
"vserverOverride",
".",
"State",
"(",
")",
")",
":",
"v",
".",
"configInit",
"(",
"config",
")",
"\n",
"return",
"\n\n",
"case",
"!",
"v",
".",
"enabled",
"&&",
"vserverEnabled",
"(",
"config",
",",
"v",
".",
"vserverOverride",
".",
"State",
"(",
")",
")",
":",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"v",
")",
"\n",
"v",
".",
"configInit",
"(",
"config",
")",
"\n",
"return",
"\n\n",
"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",
"\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",
")",
"\n",
"v",
".",
"downAll",
"(",
")",
"\n",
"v",
".",
"unconfigureVIPs",
"(",
")",
"\n",
"v",
".",
"configInit",
"(",
"config",
")",
"\n",
"return",
"\n",
"}",
"\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",
"// Preserve stats if this is a reinit",
"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",
",",
"svc",
",",
"newSvc",
".",
"ip",
")",
"\n",
"v",
".",
"deleteService",
"(",
"svc",
")",
"\n",
"}",
"\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"v",
",",
"newSvc",
")",
"\n",
"v",
".",
"services",
"[",
"svcKey",
"]",
"=",
"newSvc",
"\n",
"v",
".",
"updateState",
"(",
"newSvc",
".",
"ip",
")",
"\n",
"}",
"\n\n",
"for",
"svcKey",
",",
"svc",
":=",
"range",
"v",
".",
"services",
"{",
"if",
"newSvcs",
"[",
"svcKey",
"]",
"==",
"nil",
"{",
"// Service no longer exists",
"v",
".",
"deleteService",
"(",
"svc",
")",
"\n",
"continue",
"\n",
"}",
"\n\n",
"// Update destinations for this service",
"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",
",",
"svc",
",",
"newDest",
")",
"\n",
"svc",
".",
"dests",
"[",
"destKey",
"]",
"=",
"newDest",
"\n",
"}",
"\n\n",
"for",
"destKey",
",",
"dest",
":=",
"range",
"svc",
".",
"dests",
"{",
"if",
"newDests",
"[",
"destKey",
"]",
"==",
"nil",
"{",
"// Destination no longer exists",
"if",
"dest",
".",
"active",
"{",
"dest",
".",
"healthy",
"=",
"false",
"\n",
"svc",
".",
"updateState",
"(",
")",
"\n",
"}",
"\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"v",
",",
"svc",
",",
"dest",
")",
"\n",
"delete",
"(",
"svc",
".",
"dests",
",",
"destKey",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"// 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",
")",
"\n",
"for",
"_",
",",
"svc",
":=",
"range",
"v",
".",
"services",
"{",
"needVIPs",
"[",
"svc",
".",
"ip",
"]",
"=",
"true",
"\n",
"}",
"\n",
"for",
"vip",
":=",
"range",
"v",
".",
"vips",
"{",
"if",
"!",
"needVIPs",
"[",
"vip",
".",
"IP",
"]",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"v",
",",
"vip",
".",
"IP",
")",
"\n",
"v",
".",
"unconfigureVIP",
"(",
"&",
"vip",
")",
"\n",
"}",
"\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",
"// TODO(baptr): Should this only happen if it's enabled?",
"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",
",",
"s",
")",
"\n",
"delete",
"(",
"v",
".",
"services",
",",
"s",
".",
"serviceKey",
")",
"\n",
"// TODO(baptr): Once service contains seesaw.VIP, move check and",
"// unconfigureVIP here.",
"}"
] | // 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",
",",
"n",
".",
"description",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"check",
":=",
"v",
".",
"checks",
"[",
"n",
".",
"key",
"]",
"\n",
"if",
"check",
"==",
"nil",
"{",
"log",
".",
"Warningf",
"(",
"\"",
"\"",
",",
"v",
",",
"n",
".",
"key",
")",
"\n",
"return",
"\n",
"}",
"\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",
",",
"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",
"{",
"// No change",
"return",
"\n",
"}",
"\n",
"v",
".",
"vserverOverride",
"=",
"*",
"override",
"\n",
"if",
"vserverEnabled",
"(",
"v",
".",
"config",
",",
"o",
".",
"State",
"(",
")",
")",
"==",
"v",
".",
"enabled",
"{",
"// enable state not changed - nothing to do",
"return",
"\n",
"}",
"\n",
"// TODO(angusc): handle backend and destination overrides.",
"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",
"(",
")",
"{",
"// The destination is healthy if the backend is enabled and *all* the checks",
"// for that destination are healthy.",
"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\n",
"if",
"d",
".",
"healthy",
"==",
"healthy",
"{",
"return",
"\n",
"}",
"\n",
"d",
".",
"healthy",
"=",
"healthy",
"\n\n",
"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",
"(",
")",
"\n\n",
"case",
"d",
".",
"service",
".",
"active",
"!=",
"d",
".",
"healthy",
"||",
"d",
".",
"service",
".",
"healthy",
"!=",
"d",
".",
"healthy",
":",
"// The service may need to be brought up or down.",
"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",
"(",
"\"",
"\"",
",",
"d",
".",
"service",
".",
"vserver",
",",
"d",
".",
"service",
",",
"d",
")",
"\n\n",
"ncc",
":=",
"d",
".",
"service",
".",
"vserver",
".",
"ncc",
"\n",
"if",
"err",
":=",
"ncc",
".",
"Dial",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"d",
".",
"service",
".",
"vserver",
",",
"err",
")",
"\n",
"}",
"\n",
"defer",
"ncc",
".",
"Close",
"(",
")",
"\n",
"if",
"err",
":=",
"ncc",
".",
"IPVSAddDestination",
"(",
"d",
".",
"service",
".",
"ipvsSvc",
",",
"d",
".",
"ipvsDst",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"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",
"(",
"\"",
"\"",
",",
"d",
".",
"service",
".",
"vserver",
",",
"d",
".",
"service",
",",
"d",
")",
"\n\n",
"ncc",
":=",
"d",
".",
"service",
".",
"vserver",
".",
"ncc",
"\n",
"if",
"err",
":=",
"ncc",
".",
"Dial",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"d",
".",
"service",
".",
"vserver",
",",
"err",
")",
"\n",
"}",
"\n",
"defer",
"ncc",
".",
"Close",
"(",
")",
"\n",
"if",
"err",
":=",
"ncc",
".",
"IPVSDeleteDestination",
"(",
"d",
".",
"service",
".",
"ipvsSvc",
",",
"d",
".",
"ipvsDst",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"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",
"(",
"\"",
"\"",
",",
"d",
".",
"service",
".",
"vserver",
",",
"d",
",",
"dest",
",",
"d",
".",
"destinationKey",
",",
"dest",
".",
"destinationKey",
")",
"\n",
"}",
"\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"d",
".",
"service",
".",
"vserver",
",",
"d",
".",
"service",
",",
"d",
")",
"\n\n",
"updateIPVS",
":=",
"d",
".",
"active",
"&&",
"!",
"d",
".",
"ipvsEqual",
"(",
"dest",
")",
"\n\n",
"dest",
".",
"active",
"=",
"d",
".",
"active",
"\n",
"dest",
".",
"healthy",
"=",
"d",
".",
"healthy",
"\n",
"dest",
".",
"stats",
"=",
"d",
".",
"stats",
"\n",
"*",
"d",
"=",
"*",
"dest",
"\n\n",
"if",
"!",
"d",
".",
"healthy",
"{",
"return",
"\n",
"}",
"\n\n",
"if",
"!",
"d",
".",
"backend",
".",
"Enabled",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"d",
".",
"service",
".",
"vserver",
",",
"d",
".",
"service",
",",
"d",
")",
"\n",
"d",
".",
"healthy",
"=",
"false",
"\n",
"d",
".",
"service",
".",
"updateState",
"(",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"if",
"!",
"updateIPVS",
"{",
"return",
"\n",
"}",
"\n\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"d",
".",
"service",
".",
"vserver",
",",
"d",
".",
"service",
",",
"d",
")",
"\n",
"ncc",
":=",
"d",
".",
"service",
".",
"vserver",
".",
"ncc",
"\n",
"if",
"err",
":=",
"ncc",
".",
"Dial",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"d",
".",
"service",
".",
"vserver",
",",
"err",
")",
"\n",
"}",
"\n",
"defer",
"ncc",
".",
"Close",
"(",
")",
"\n\n",
"if",
"err",
":=",
"ncc",
".",
"IPVSUpdateDestination",
"(",
"d",
".",
"service",
".",
"ipvsSvc",
",",
"d",
".",
"ipvsDst",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"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",
"(",
")",
"{",
"// 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",
"\n",
"numHealthyDests",
":=",
"0",
"\n",
"for",
"_",
",",
"d",
":=",
"range",
"s",
".",
"dests",
"{",
"if",
"d",
".",
"backend",
".",
"InService",
"{",
"numBackends",
"++",
"\n",
"}",
"\n",
"if",
"d",
".",
"healthy",
"{",
"numHealthyDests",
"++",
"\n",
"}",
"\n",
"}",
"\n\n",
"threshold",
":=",
"s",
".",
"ventry",
".",
"LowWatermark",
"\n",
"if",
"!",
"s",
".",
"healthy",
"{",
"threshold",
"=",
"s",
".",
"ventry",
".",
"HighWatermark",
"\n",
"}",
"\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\n",
"if",
"s",
".",
"healthy",
"==",
"healthy",
"{",
"// no change in service state, just update destinations",
"s",
".",
"updateDests",
"(",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"oldHealth",
":=",
"\"",
"\"",
"\n",
"newHealth",
":=",
"\"",
"\"",
"\n",
"if",
"s",
".",
"healthy",
"{",
"oldHealth",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"if",
"healthy",
"{",
"newHealth",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"s",
".",
"vserver",
",",
"s",
",",
"numHealthyDests",
",",
"numBackends",
",",
"oldHealth",
",",
"newHealth",
")",
"\n",
"s",
".",
"healthy",
"=",
"healthy",
"\n",
"vserverActive",
":=",
"s",
".",
"vserver",
".",
"active",
"[",
"s",
".",
"ip",
"]",
"\n\n",
"switch",
"{",
"case",
"vserverActive",
"&&",
"s",
".",
"healthy",
":",
"// The vserver is already active. Bringing up the service will have no",
"// effect on the vserver state.",
"s",
".",
"up",
"(",
")",
"\n\n",
"case",
"vserverActive",
"!=",
"s",
".",
"healthy",
":",
"// The vserver may need to be brought up or down.",
"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",
"(",
"\"",
"\"",
",",
"s",
".",
"vserver",
",",
"s",
")",
"\n\n",
"ncc",
":=",
"s",
".",
"vserver",
".",
"ncc",
"\n",
"if",
"err",
":=",
"ncc",
".",
"Dial",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"s",
".",
"vserver",
",",
"err",
")",
"\n",
"}",
"\n",
"defer",
"ncc",
".",
"Close",
"(",
")",
"\n\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"s",
".",
"vserver",
",",
"s",
".",
"ipvsSvc",
")",
"\n",
"if",
"err",
":=",
"ncc",
".",
"IPVSAddService",
"(",
"s",
".",
"ipvsSvc",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"s",
".",
"vserver",
",",
"s",
",",
"err",
")",
"\n",
"}",
"\n\n",
"// Update destinations *after* the IPVS service exists.",
"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",
"(",
"\"",
"\"",
",",
"s",
".",
"vserver",
",",
"s",
")",
"\n\n",
"ncc",
":=",
"s",
".",
"vserver",
".",
"ncc",
"\n",
"if",
"err",
":=",
"ncc",
".",
"Dial",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"s",
".",
"vserver",
",",
"err",
")",
"\n",
"}",
"\n",
"defer",
"ncc",
".",
"Close",
"(",
")",
"\n\n",
"// Remove IPVS destinations *before* the IPVS service is removed.",
"s",
".",
"updateDests",
"(",
")",
"\n\n",
"if",
"err",
":=",
"ncc",
".",
"IPVSDeleteService",
"(",
"s",
".",
"ipvsSvc",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"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",
"(",
"\"",
"\"",
",",
"s",
".",
"vserver",
",",
"s",
",",
"svc",
",",
"s",
".",
"serviceKey",
",",
"svc",
".",
"serviceKey",
")",
"\n",
"}",
"\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"s",
".",
"vserver",
",",
"s",
")",
"\n\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\n",
"if",
"!",
"updateIPVS",
"{",
"return",
"\n",
"}",
"\n\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"s",
".",
"vserver",
",",
"s",
")",
"\n",
"ncc",
":=",
"s",
".",
"vserver",
".",
"ncc",
"\n",
"if",
"err",
":=",
"ncc",
".",
"Dial",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"s",
".",
"vserver",
",",
"err",
")",
"\n",
"}",
"\n",
"defer",
"ncc",
".",
"Close",
"(",
")",
"\n\n",
"if",
"err",
":=",
"ncc",
".",
"IPVSUpdateService",
"(",
"s",
".",
"ipvsSvc",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"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",
"(",
"\"",
"\"",
",",
"s",
".",
"vserver",
",",
"s",
")",
"\n\n",
"ncc",
":=",
"s",
".",
"vserver",
".",
"ncc",
"\n",
"if",
"err",
":=",
"ncc",
".",
"Dial",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"s",
".",
"vserver",
",",
"err",
")",
"\n",
"}",
"\n",
"defer",
"ncc",
".",
"Close",
"(",
")",
"\n\n",
"ipvsSvc",
",",
"err",
":=",
"ncc",
".",
"IPVSGetService",
"(",
"s",
".",
"ipvsSvc",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Warningf",
"(",
"\"",
"\"",
",",
"s",
".",
"vserver",
",",
"s",
",",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n",
"s",
".",
"stats",
".",
"ServiceStats",
"=",
"ipvsSvc",
".",
"Statistics",
"\n\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",
"(",
"\"",
"\"",
",",
"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\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\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",
")",
"{",
"// 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",
"\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\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",
",",
"err",
")",
"\n",
"}",
"\n",
"defer",
"ncc",
".",
"Close",
"(",
")",
"\n\n",
"v",
".",
"active",
"[",
"ip",
"]",
"=",
"true",
"\n",
"v",
".",
"updateServices",
"(",
"ip",
")",
"\n\n",
"// If this is an anycast VIP, start advertising a BGP route.",
"nip",
":=",
"ip",
".",
"IP",
"(",
")",
"\n",
"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",
"(",
")",
"\n",
"lbVserver",
".",
"Services",
"=",
"nil",
"\n",
"lbVserver",
".",
"Warnings",
"=",
"nil",
"\n",
"if",
"err",
":=",
"v",
".",
"engine",
".",
"lbInterface",
".",
"AddVserver",
"(",
"lbVserver",
",",
"ip",
".",
"AF",
"(",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"v",
",",
"err",
")",
"\n",
"}",
"\n",
"v",
".",
"lbVservers",
"[",
"ip",
"]",
"=",
"lbVserver",
"\n\n",
"vip",
":=",
"seesaw",
".",
"NewVIP",
"(",
"nip",
",",
"nil",
")",
"\n",
"if",
"err",
":=",
"v",
".",
"engine",
".",
"lbInterface",
".",
"AddVIP",
"(",
"vip",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"v",
",",
"ip",
",",
"err",
")",
"\n",
"}",
"\n",
"// TODO(angusc): Filter out anycast VIPs for non-anycast clusters further",
"// upstream.",
"if",
"v",
".",
"engine",
".",
"config",
".",
"AnycastEnabled",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"v",
",",
"ip",
")",
"\n",
"if",
"err",
":=",
"ncc",
".",
"BGPAdvertiseVIP",
"(",
"nip",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"v",
",",
"ip",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"else",
"{",
"log",
".",
"Warningf",
"(",
"\"",
"\"",
",",
"v",
",",
"ip",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"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",
",",
"err",
")",
"\n",
"}",
"\n",
"defer",
"ncc",
".",
"Close",
"(",
")",
"\n\n",
"// If this is an anycast VIP, withdraw the BGP route.",
"nip",
":=",
"ip",
".",
"IP",
"(",
")",
"\n",
"if",
"seesaw",
".",
"IsAnycast",
"(",
"nip",
")",
"{",
"if",
"v",
".",
"engine",
".",
"config",
".",
"AnycastEnabled",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"v",
",",
"ip",
")",
"\n",
"if",
"err",
":=",
"ncc",
".",
"BGPWithdrawVIP",
"(",
"nip",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"v",
",",
"ip",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"vip",
":=",
"seesaw",
".",
"NewVIP",
"(",
"nip",
",",
"nil",
")",
"\n",
"if",
"err",
":=",
"v",
".",
"engine",
".",
"lbInterface",
".",
"DeleteVIP",
"(",
"vip",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"v",
",",
"ip",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"v",
".",
"engine",
".",
"lbInterface",
".",
"DeleteVserver",
"(",
"v",
".",
"lbVservers",
"[",
"ip",
"]",
",",
"ip",
".",
"AF",
"(",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"v",
",",
"err",
")",
"\n",
"}",
"\n",
"delete",
"(",
"v",
".",
"lbVservers",
",",
"ip",
")",
"\n",
"}",
"\n",
"// TODO(jsing): Should we delay while the BGP routes propagate?",
"delete",
"(",
"v",
".",
"active",
",",
"ip",
")",
"\n",
"v",
".",
"updateServices",
"(",
"ip",
")",
"\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"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",
",",
"err",
")",
"\n",
"}",
"\n",
"defer",
"ncc",
".",
"Close",
"(",
")",
"\n\n",
"// 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",
"\n",
"}",
"\n",
"// TODO(angusc): Set up anycast Vservers here as well (without bringing up the VIP).",
"if",
"vip",
".",
"Type",
"==",
"seesaw",
".",
"AnycastVIP",
"{",
"continue",
"\n",
"}",
"\n\n",
"// TODO(jsing): Create a ncc.LBVserver that only encapsulates",
"// the necessary state, rather than storing a full vserver",
"// snapshot.",
"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",
",",
"err",
")",
"\n",
"}",
"\n",
"v",
".",
"lbVservers",
"[",
"vip",
".",
"IP",
"]",
"=",
"lbVserver",
"\n\n",
"if",
"err",
":=",
"v",
".",
"engine",
".",
"lbInterface",
".",
"AddVIP",
"(",
"vip",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"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",
",",
"err",
")",
"\n",
"}",
"\n",
"defer",
"ncc",
".",
"Close",
"(",
")",
"\n\n",
"if",
"err",
":=",
"v",
".",
"engine",
".",
"lbInterface",
".",
"DeleteVIP",
"(",
"vip",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"v",
",",
"vip",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"v",
".",
"engine",
".",
"lbInterface",
".",
"DeleteVserver",
"(",
"v",
".",
"lbVservers",
"[",
"vip",
".",
"IP",
"]",
",",
"vip",
".",
"IP",
".",
"AF",
"(",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"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",
",",
"err",
")",
"\n",
"}",
"\n",
"defer",
"ncc",
".",
"Close",
"(",
")",
"\n\n",
"// 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",
")",
"\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",
")",
"{",
"// TODO(angusc): connection timeout?",
"tcpAddr",
":=",
"&",
"net",
".",
"TCPAddr",
"{",
"IP",
":",
"ip",
",",
"Port",
":",
"f",
".",
"port",
"}",
"\n",
"tcpConn",
",",
"err",
":=",
"net",
".",
"DialTCP",
"(",
"\"",
"\"",
",",
"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\n",
"client",
":=",
"&",
"http",
".",
"Client",
"{",
"CheckRedirect",
":",
"func",
"(",
"req",
"*",
"http",
".",
"Request",
",",
"via",
"[",
"]",
"*",
"http",
".",
"Request",
")",
"error",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
",",
"Transport",
":",
"&",
"http",
".",
"Transport",
"{",
"Dial",
":",
"dialer",
",",
"DisableKeepAlives",
":",
"true",
",",
"TLSClientConfig",
":",
"&",
"tls",
".",
"Config",
"{",
"RootCAs",
":",
"f",
".",
"certs",
",",
"}",
",",
"}",
",",
"}",
"\n\n",
"req",
",",
"err",
":=",
"http",
".",
"NewRequest",
"(",
"\"",
"\"",
",",
"url",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"req",
".",
"Header",
".",
"Add",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n\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",
"(",
"\"",
"\"",
",",
"resp",
".",
"Status",
")",
"\n",
"}",
"\n",
"if",
"ct",
":=",
"resp",
".",
"Header",
".",
"Get",
"(",
"\"",
"\"",
")",
";",
"ct",
"!=",
"contentType",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"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 |
google/seesaw | netlink/netlink.go | uint32FromNetwork | func uint32FromNetwork(u uint32) uint32 {
b := *(*[4]byte)(unsafe.Pointer(&u))
return binary.BigEndian.Uint32(b[:])
} | go | func uint32FromNetwork(u uint32) uint32 {
b := *(*[4]byte)(unsafe.Pointer(&u))
return binary.BigEndian.Uint32(b[:])
} | [
"func",
"uint32FromNetwork",
"(",
"u",
"uint32",
")",
"uint32",
"{",
"b",
":=",
"*",
"(",
"*",
"[",
"4",
"]",
"byte",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"u",
")",
")",
"\n",
"return",
"binary",
".",
"BigEndian",
".",
"Uint32",
"(",
"b",
"[",
":",
"]",
")",
"\n",
"}"
] | // uint32FromNetwork converts the given value from its network byte order. | [
"uint32FromNetwork",
"converts",
"the",
"given",
"value",
"from",
"its",
"network",
"byte",
"order",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/netlink/netlink.go#L61-L64 | train |
google/seesaw | netlink/netlink.go | uint32ToNetwork | func uint32ToNetwork(u uint32) uint32 {
var b [4]byte
binary.BigEndian.PutUint32(b[:], u)
return *(*uint32)(unsafe.Pointer(&b))
} | go | func uint32ToNetwork(u uint32) uint32 {
var b [4]byte
binary.BigEndian.PutUint32(b[:], u)
return *(*uint32)(unsafe.Pointer(&b))
} | [
"func",
"uint32ToNetwork",
"(",
"u",
"uint32",
")",
"uint32",
"{",
"var",
"b",
"[",
"4",
"]",
"byte",
"\n",
"binary",
".",
"BigEndian",
".",
"PutUint32",
"(",
"b",
"[",
":",
"]",
",",
"u",
")",
"\n",
"return",
"*",
"(",
"*",
"uint32",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"b",
")",
")",
"\n",
"}"
] | // uint32ToNetwork converts the given value to its network byte order. | [
"uint32ToNetwork",
"converts",
"the",
"given",
"value",
"to",
"its",
"network",
"byte",
"order",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/netlink/netlink.go#L67-L71 | train |
google/seesaw | netlink/netlink.go | uint64FromNetwork | func uint64FromNetwork(u uint64) uint64 {
b := *(*[8]byte)(unsafe.Pointer(&u))
return binary.BigEndian.Uint64(b[:])
} | go | func uint64FromNetwork(u uint64) uint64 {
b := *(*[8]byte)(unsafe.Pointer(&u))
return binary.BigEndian.Uint64(b[:])
} | [
"func",
"uint64FromNetwork",
"(",
"u",
"uint64",
")",
"uint64",
"{",
"b",
":=",
"*",
"(",
"*",
"[",
"8",
"]",
"byte",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"u",
")",
")",
"\n",
"return",
"binary",
".",
"BigEndian",
".",
"Uint64",
"(",
"b",
"[",
":",
"]",
")",
"\n",
"}"
] | // uint64FromNetwork converts the given value from its network byte order. | [
"uint64FromNetwork",
"converts",
"the",
"given",
"value",
"from",
"its",
"network",
"byte",
"order",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/netlink/netlink.go#L74-L77 | train |
google/seesaw | netlink/netlink.go | uint64ToNetwork | func uint64ToNetwork(u uint64) uint64 {
var b [8]byte
binary.BigEndian.PutUint64(b[:], u)
return *(*uint64)(unsafe.Pointer(&b))
} | go | func uint64ToNetwork(u uint64) uint64 {
var b [8]byte
binary.BigEndian.PutUint64(b[:], u)
return *(*uint64)(unsafe.Pointer(&b))
} | [
"func",
"uint64ToNetwork",
"(",
"u",
"uint64",
")",
"uint64",
"{",
"var",
"b",
"[",
"8",
"]",
"byte",
"\n",
"binary",
".",
"BigEndian",
".",
"PutUint64",
"(",
"b",
"[",
":",
"]",
",",
"u",
")",
"\n",
"return",
"*",
"(",
"*",
"uint64",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"b",
")",
")",
"\n",
"}"
] | // uint64ToNetwork converts the given value to its network byte order. | [
"uint64ToNetwork",
"converts",
"the",
"given",
"value",
"to",
"its",
"network",
"byte",
"order",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/netlink/netlink.go#L80-L84 | train |
google/seesaw | netlink/netlink.go | structMaxAttrID | func structMaxAttrID(v reflect.Value) (uint16, error) {
if v.Kind() != reflect.Struct {
return 0, fmt.Errorf("%v is not a struct", v.Type())
}
st := v.Type()
var maxAttrID uint16
for i := 0; i < st.NumField(); i++ {
ft, fv := st.Field(i), v.Field(i)
fp, err := parseFieldParams(ft.Tag.Get("netlink"))
if err != nil {
return 0, err
}
if fp != nil && fp.attr > maxAttrID {
maxAttrID = fp.attr
}
if fp == nil && fv.Kind() == reflect.Struct {
attrID, err := structMaxAttrID(fv)
if err != nil {
return 0, err
}
if attrID > maxAttrID {
maxAttrID = attrID
}
}
}
return maxAttrID, nil
} | go | func structMaxAttrID(v reflect.Value) (uint16, error) {
if v.Kind() != reflect.Struct {
return 0, fmt.Errorf("%v is not a struct", v.Type())
}
st := v.Type()
var maxAttrID uint16
for i := 0; i < st.NumField(); i++ {
ft, fv := st.Field(i), v.Field(i)
fp, err := parseFieldParams(ft.Tag.Get("netlink"))
if err != nil {
return 0, err
}
if fp != nil && fp.attr > maxAttrID {
maxAttrID = fp.attr
}
if fp == nil && fv.Kind() == reflect.Struct {
attrID, err := structMaxAttrID(fv)
if err != nil {
return 0, err
}
if attrID > maxAttrID {
maxAttrID = attrID
}
}
}
return maxAttrID, nil
} | [
"func",
"structMaxAttrID",
"(",
"v",
"reflect",
".",
"Value",
")",
"(",
"uint16",
",",
"error",
")",
"{",
"if",
"v",
".",
"Kind",
"(",
")",
"!=",
"reflect",
".",
"Struct",
"{",
"return",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"v",
".",
"Type",
"(",
")",
")",
"\n",
"}",
"\n",
"st",
":=",
"v",
".",
"Type",
"(",
")",
"\n\n",
"var",
"maxAttrID",
"uint16",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"st",
".",
"NumField",
"(",
")",
";",
"i",
"++",
"{",
"ft",
",",
"fv",
":=",
"st",
".",
"Field",
"(",
"i",
")",
",",
"v",
".",
"Field",
"(",
"i",
")",
"\n",
"fp",
",",
"err",
":=",
"parseFieldParams",
"(",
"ft",
".",
"Tag",
".",
"Get",
"(",
"\"",
"\"",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"if",
"fp",
"!=",
"nil",
"&&",
"fp",
".",
"attr",
">",
"maxAttrID",
"{",
"maxAttrID",
"=",
"fp",
".",
"attr",
"\n",
"}",
"\n",
"if",
"fp",
"==",
"nil",
"&&",
"fv",
".",
"Kind",
"(",
")",
"==",
"reflect",
".",
"Struct",
"{",
"attrID",
",",
"err",
":=",
"structMaxAttrID",
"(",
"fv",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"if",
"attrID",
">",
"maxAttrID",
"{",
"maxAttrID",
"=",
"attrID",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"maxAttrID",
",",
"nil",
"\n",
"}"
] | // structMaxAttrID returns the maximum attribute ID found on netlink tagged
// fields within the given struct and any untagged structs it contains. | [
"structMaxAttrID",
"returns",
"the",
"maximum",
"attribute",
"ID",
"found",
"on",
"netlink",
"tagged",
"fields",
"within",
"the",
"given",
"struct",
"and",
"any",
"untagged",
"structs",
"it",
"contains",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/netlink/netlink.go#L130-L157 | train |
google/seesaw | netlink/netlink.go | Error | func (e *Error) Error() string {
nle := C.GoString(C.nl_geterror(e.errno))
return fmt.Sprintf("%s: %s", e.msg, strings.ToLower(nle))
} | go | func (e *Error) Error() string {
nle := C.GoString(C.nl_geterror(e.errno))
return fmt.Sprintf("%s: %s", e.msg, strings.ToLower(nle))
} | [
"func",
"(",
"e",
"*",
"Error",
")",
"Error",
"(",
")",
"string",
"{",
"nle",
":=",
"C",
".",
"GoString",
"(",
"C",
".",
"nl_geterror",
"(",
"e",
".",
"errno",
")",
")",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"e",
".",
"msg",
",",
"strings",
".",
"ToLower",
"(",
"nle",
")",
")",
"\n",
"}"
] | // Error returns the string representation of a netlink error. | [
"Error",
"returns",
"the",
"string",
"representation",
"of",
"a",
"netlink",
"error",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/netlink/netlink.go#L539-L542 | train |
google/seesaw | netlink/netlink.go | Family | func Family(name string) (int, error) {
s, err := newSocket()
if err != nil {
return -1, err
}
defer s.free()
if errno := C.genl_connect(s.nls); errno != 0 {
return -1, &Error{errno, "failed to connect to netlink"}
}
defer C.nl_close((*C.struct_nl_sock)(s.nls))
cn := C.CString(name)
defer C.free(unsafe.Pointer(cn))
family := C.genl_ctrl_resolve(s.nls, cn)
if family < 0 {
return -1, errors.New("failed to resolve family name")
}
return int(family), nil
} | go | func Family(name string) (int, error) {
s, err := newSocket()
if err != nil {
return -1, err
}
defer s.free()
if errno := C.genl_connect(s.nls); errno != 0 {
return -1, &Error{errno, "failed to connect to netlink"}
}
defer C.nl_close((*C.struct_nl_sock)(s.nls))
cn := C.CString(name)
defer C.free(unsafe.Pointer(cn))
family := C.genl_ctrl_resolve(s.nls, cn)
if family < 0 {
return -1, errors.New("failed to resolve family name")
}
return int(family), nil
} | [
"func",
"Family",
"(",
"name",
"string",
")",
"(",
"int",
",",
"error",
")",
"{",
"s",
",",
"err",
":=",
"newSocket",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"-",
"1",
",",
"err",
"\n",
"}",
"\n",
"defer",
"s",
".",
"free",
"(",
")",
"\n\n",
"if",
"errno",
":=",
"C",
".",
"genl_connect",
"(",
"s",
".",
"nls",
")",
";",
"errno",
"!=",
"0",
"{",
"return",
"-",
"1",
",",
"&",
"Error",
"{",
"errno",
",",
"\"",
"\"",
"}",
"\n",
"}",
"\n",
"defer",
"C",
".",
"nl_close",
"(",
"(",
"*",
"C",
".",
"struct_nl_sock",
")",
"(",
"s",
".",
"nls",
")",
")",
"\n\n",
"cn",
":=",
"C",
".",
"CString",
"(",
"name",
")",
"\n",
"defer",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"cn",
")",
")",
"\n",
"family",
":=",
"C",
".",
"genl_ctrl_resolve",
"(",
"s",
".",
"nls",
",",
"cn",
")",
"\n",
"if",
"family",
"<",
"0",
"{",
"return",
"-",
"1",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"int",
"(",
"family",
")",
",",
"nil",
"\n",
"}"
] | // Family returns the family identifier for the specified family name. | [
"Family",
"returns",
"the",
"family",
"identifier",
"for",
"the",
"specified",
"family",
"name",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/netlink/netlink.go#L545-L564 | train |
google/seesaw | ncc/ip.go | validateInterface | func validateInterface(iface *net.Interface) error {
if !ifaceNameRegexp.MatchString(iface.Name) {
return fmt.Errorf("Invalid interface name %q", iface.Name)
}
return nil
} | go | func validateInterface(iface *net.Interface) error {
if !ifaceNameRegexp.MatchString(iface.Name) {
return fmt.Errorf("Invalid interface name %q", iface.Name)
}
return nil
} | [
"func",
"validateInterface",
"(",
"iface",
"*",
"net",
".",
"Interface",
")",
"error",
"{",
"if",
"!",
"ifaceNameRegexp",
".",
"MatchString",
"(",
"iface",
".",
"Name",
")",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"iface",
".",
"Name",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // validateInterface validates the name of a network interface. | [
"validateInterface",
"validates",
"the",
"name",
"of",
"a",
"network",
"interface",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/ip.go#L45-L50 | train |
google/seesaw | ncc/ip.go | ifaceDown | func ifaceDown(pIface *net.Interface) error {
out, err := ipRunOutput("link show dev %s", pIface.Name)
if !strings.Contains(out, "state UP") {
return nil
}
// Unlike IPv4, the kernel removes IPv6 addresses when the link goes down. We
// don't want that behavior, so we have to preserve the addresses manually.
// TODO(angusc): See if we can get a sysctl or something added to the kernel
// so we can avoid doing this.
ipv6Addrs := make(map[string]*net.Interface)
ifaces, err := vlanInterfaces(pIface)
if err != nil {
return err
}
ifaces = append(ifaces, pIface)
for _, iface := range ifaces {
out, err = ipRunOutput("-6 addr show dev %s scope global", iface.Name)
for _, line := range strings.Split(out, "\n") {
if match := ipv6AddrRegexp.FindStringSubmatch(line); match != nil {
ipv6Addrs[match[1]] = iface
}
}
}
if err := ifaceFastDown(pIface); err != nil {
return err
}
for addr, iface := range ipv6Addrs {
if err := ipRunIface(iface, "addr add %s dev %s", addr, iface.Name); err != nil {
return err
}
}
return nil
} | go | func ifaceDown(pIface *net.Interface) error {
out, err := ipRunOutput("link show dev %s", pIface.Name)
if !strings.Contains(out, "state UP") {
return nil
}
// Unlike IPv4, the kernel removes IPv6 addresses when the link goes down. We
// don't want that behavior, so we have to preserve the addresses manually.
// TODO(angusc): See if we can get a sysctl or something added to the kernel
// so we can avoid doing this.
ipv6Addrs := make(map[string]*net.Interface)
ifaces, err := vlanInterfaces(pIface)
if err != nil {
return err
}
ifaces = append(ifaces, pIface)
for _, iface := range ifaces {
out, err = ipRunOutput("-6 addr show dev %s scope global", iface.Name)
for _, line := range strings.Split(out, "\n") {
if match := ipv6AddrRegexp.FindStringSubmatch(line); match != nil {
ipv6Addrs[match[1]] = iface
}
}
}
if err := ifaceFastDown(pIface); err != nil {
return err
}
for addr, iface := range ipv6Addrs {
if err := ipRunIface(iface, "addr add %s dev %s", addr, iface.Name); err != nil {
return err
}
}
return nil
} | [
"func",
"ifaceDown",
"(",
"pIface",
"*",
"net",
".",
"Interface",
")",
"error",
"{",
"out",
",",
"err",
":=",
"ipRunOutput",
"(",
"\"",
"\"",
",",
"pIface",
".",
"Name",
")",
"\n",
"if",
"!",
"strings",
".",
"Contains",
"(",
"out",
",",
"\"",
"\"",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"// Unlike IPv4, the kernel removes IPv6 addresses when the link goes down. We",
"// don't want that behavior, so we have to preserve the addresses manually.",
"// TODO(angusc): See if we can get a sysctl or something added to the kernel",
"// so we can avoid doing this.",
"ipv6Addrs",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"net",
".",
"Interface",
")",
"\n",
"ifaces",
",",
"err",
":=",
"vlanInterfaces",
"(",
"pIface",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"ifaces",
"=",
"append",
"(",
"ifaces",
",",
"pIface",
")",
"\n",
"for",
"_",
",",
"iface",
":=",
"range",
"ifaces",
"{",
"out",
",",
"err",
"=",
"ipRunOutput",
"(",
"\"",
"\"",
",",
"iface",
".",
"Name",
")",
"\n",
"for",
"_",
",",
"line",
":=",
"range",
"strings",
".",
"Split",
"(",
"out",
",",
"\"",
"\\n",
"\"",
")",
"{",
"if",
"match",
":=",
"ipv6AddrRegexp",
".",
"FindStringSubmatch",
"(",
"line",
")",
";",
"match",
"!=",
"nil",
"{",
"ipv6Addrs",
"[",
"match",
"[",
"1",
"]",
"]",
"=",
"iface",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"err",
":=",
"ifaceFastDown",
"(",
"pIface",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"for",
"addr",
",",
"iface",
":=",
"range",
"ipv6Addrs",
"{",
"if",
"err",
":=",
"ipRunIface",
"(",
"iface",
",",
"\"",
"\"",
",",
"addr",
",",
"iface",
".",
"Name",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // ifaceDown sets the interface link state to down and preserves IPv6 addresses
// for both the given interface and any associated VLAN interfaces. | [
"ifaceDown",
"sets",
"the",
"interface",
"link",
"state",
"to",
"down",
"and",
"preserves",
"IPv6",
"addresses",
"for",
"both",
"the",
"given",
"interface",
"and",
"any",
"associated",
"VLAN",
"interfaces",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/ip.go#L106-L139 | train |
google/seesaw | ncc/ip.go | ifaceSetMAC | func ifaceSetMAC(iface *net.Interface) error {
return ipRunIface(iface, "link set %s address %s", iface.Name, iface.HardwareAddr)
} | go | func ifaceSetMAC(iface *net.Interface) error {
return ipRunIface(iface, "link set %s address %s", iface.Name, iface.HardwareAddr)
} | [
"func",
"ifaceSetMAC",
"(",
"iface",
"*",
"net",
".",
"Interface",
")",
"error",
"{",
"return",
"ipRunIface",
"(",
"iface",
",",
"\"",
"\"",
",",
"iface",
".",
"Name",
",",
"iface",
".",
"HardwareAddr",
")",
"\n",
"}"
] | // ifaceSetMAC sets the interface MAC address. | [
"ifaceSetMAC",
"sets",
"the",
"interface",
"MAC",
"address",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/ip.go#L153-L155 | train |
google/seesaw | ncc/ip.go | ifaceAddIPAddr | func ifaceAddIPAddr(iface *net.Interface, ip net.IP, mask net.IPMask) error {
if ip.To4() != nil {
return ifaceAddIPv4Addr(iface, ip, mask)
}
return ifaceAddIPv6Addr(iface, ip, mask)
} | go | func ifaceAddIPAddr(iface *net.Interface, ip net.IP, mask net.IPMask) error {
if ip.To4() != nil {
return ifaceAddIPv4Addr(iface, ip, mask)
}
return ifaceAddIPv6Addr(iface, ip, mask)
} | [
"func",
"ifaceAddIPAddr",
"(",
"iface",
"*",
"net",
".",
"Interface",
",",
"ip",
"net",
".",
"IP",
",",
"mask",
"net",
".",
"IPMask",
")",
"error",
"{",
"if",
"ip",
".",
"To4",
"(",
")",
"!=",
"nil",
"{",
"return",
"ifaceAddIPv4Addr",
"(",
"iface",
",",
"ip",
",",
"mask",
")",
"\n",
"}",
"\n",
"return",
"ifaceAddIPv6Addr",
"(",
"iface",
",",
"ip",
",",
"mask",
")",
"\n",
"}"
] | // ifaceAddIPAddr adds the given IP address to the network interface. | [
"ifaceAddIPAddr",
"adds",
"the",
"given",
"IP",
"address",
"to",
"the",
"network",
"interface",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/ip.go#L158-L163 | train |
google/seesaw | ncc/ip.go | ifaceAddIPv4Addr | func ifaceAddIPv4Addr(iface *net.Interface, ip net.IP, mask net.IPMask) error {
if ip.To4() == nil {
return fmt.Errorf("IP %v is not a valid IPv4 address", ip)
}
brd := make(net.IP, net.IPv4len)
copy(brd, ip.To4())
for i := 0; i < net.IPv4len; i++ {
brd[i] |= ^mask[i]
}
prefixLen, _ := mask.Size()
return ipRunIface(iface, "addr add %s/%d brd %s dev %s", ip, prefixLen, brd, iface.Name)
} | go | func ifaceAddIPv4Addr(iface *net.Interface, ip net.IP, mask net.IPMask) error {
if ip.To4() == nil {
return fmt.Errorf("IP %v is not a valid IPv4 address", ip)
}
brd := make(net.IP, net.IPv4len)
copy(brd, ip.To4())
for i := 0; i < net.IPv4len; i++ {
brd[i] |= ^mask[i]
}
prefixLen, _ := mask.Size()
return ipRunIface(iface, "addr add %s/%d brd %s dev %s", ip, prefixLen, brd, iface.Name)
} | [
"func",
"ifaceAddIPv4Addr",
"(",
"iface",
"*",
"net",
".",
"Interface",
",",
"ip",
"net",
".",
"IP",
",",
"mask",
"net",
".",
"IPMask",
")",
"error",
"{",
"if",
"ip",
".",
"To4",
"(",
")",
"==",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"ip",
")",
"\n",
"}",
"\n",
"brd",
":=",
"make",
"(",
"net",
".",
"IP",
",",
"net",
".",
"IPv4len",
")",
"\n",
"copy",
"(",
"brd",
",",
"ip",
".",
"To4",
"(",
")",
")",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"net",
".",
"IPv4len",
";",
"i",
"++",
"{",
"brd",
"[",
"i",
"]",
"|=",
"^",
"mask",
"[",
"i",
"]",
"\n",
"}",
"\n",
"prefixLen",
",",
"_",
":=",
"mask",
".",
"Size",
"(",
")",
"\n",
"return",
"ipRunIface",
"(",
"iface",
",",
"\"",
"\"",
",",
"ip",
",",
"prefixLen",
",",
"brd",
",",
"iface",
".",
"Name",
")",
"\n",
"}"
] | // ifaceAddIPv4Addr adds the given IPv4 address to the network interface. | [
"ifaceAddIPv4Addr",
"adds",
"the",
"given",
"IPv4",
"address",
"to",
"the",
"network",
"interface",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/ip.go#L166-L177 | train |
google/seesaw | ncc/ip.go | ifaceAddIPv6Addr | func ifaceAddIPv6Addr(iface *net.Interface, ip net.IP, mask net.IPMask) error {
prefixLen, _ := mask.Size()
return ipRunIface(iface, "addr add %s/%d dev %s", ip, prefixLen, iface.Name)
} | go | func ifaceAddIPv6Addr(iface *net.Interface, ip net.IP, mask net.IPMask) error {
prefixLen, _ := mask.Size()
return ipRunIface(iface, "addr add %s/%d dev %s", ip, prefixLen, iface.Name)
} | [
"func",
"ifaceAddIPv6Addr",
"(",
"iface",
"*",
"net",
".",
"Interface",
",",
"ip",
"net",
".",
"IP",
",",
"mask",
"net",
".",
"IPMask",
")",
"error",
"{",
"prefixLen",
",",
"_",
":=",
"mask",
".",
"Size",
"(",
")",
"\n",
"return",
"ipRunIface",
"(",
"iface",
",",
"\"",
"\"",
",",
"ip",
",",
"prefixLen",
",",
"iface",
".",
"Name",
")",
"\n",
"}"
] | // ifaceAddIPv6Addr adds the given IPv6 address to the network interface. | [
"ifaceAddIPv6Addr",
"adds",
"the",
"given",
"IPv6",
"address",
"to",
"the",
"network",
"interface",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/ip.go#L180-L183 | train |
google/seesaw | ncc/ip.go | ifaceAddVLAN | func ifaceAddVLAN(iface *net.Interface, vlan *seesaw.VLAN) error {
name := fmt.Sprintf("%s.%d", iface.Name, vlan.ID)
err := ipRunIface(iface, "link add link %s name %s type vlan id %d", iface.Name, name, vlan.ID)
if err != nil {
return fmt.Errorf("Failed to create VLAN interface %q: %v", name, err)
}
vlanIface, err := net.InterfaceByName(name)
if err != nil {
return fmt.Errorf("Failed to find newly created VLAN interface %q: %v", name, err)
}
if err := sysctlInitIface(vlanIface.Name); err != nil {
return fmt.Errorf("Failed to initialise sysctls for VLAN interface %q: %v", name, err)
}
if vlan.IPv4Addr != nil {
if err := ifaceAddIPv4Addr(vlanIface, vlan.IPv4Addr, vlan.IPv4Mask); err != nil {
return fmt.Errorf("Failed to add %v to VLAN interface %q", vlan.IPv4Addr, name)
}
}
if vlan.IPv6Addr != nil {
if err := ifaceAddIPv6Addr(vlanIface, vlan.IPv6Addr, vlan.IPv6Mask); err != nil {
return fmt.Errorf("Failed to add %v to VLAN interface %q", vlan.IPv6Addr, name)
}
}
if iface.Flags&net.FlagUp == 0 {
return nil
}
return ifaceUp(vlanIface)
} | go | func ifaceAddVLAN(iface *net.Interface, vlan *seesaw.VLAN) error {
name := fmt.Sprintf("%s.%d", iface.Name, vlan.ID)
err := ipRunIface(iface, "link add link %s name %s type vlan id %d", iface.Name, name, vlan.ID)
if err != nil {
return fmt.Errorf("Failed to create VLAN interface %q: %v", name, err)
}
vlanIface, err := net.InterfaceByName(name)
if err != nil {
return fmt.Errorf("Failed to find newly created VLAN interface %q: %v", name, err)
}
if err := sysctlInitIface(vlanIface.Name); err != nil {
return fmt.Errorf("Failed to initialise sysctls for VLAN interface %q: %v", name, err)
}
if vlan.IPv4Addr != nil {
if err := ifaceAddIPv4Addr(vlanIface, vlan.IPv4Addr, vlan.IPv4Mask); err != nil {
return fmt.Errorf("Failed to add %v to VLAN interface %q", vlan.IPv4Addr, name)
}
}
if vlan.IPv6Addr != nil {
if err := ifaceAddIPv6Addr(vlanIface, vlan.IPv6Addr, vlan.IPv6Mask); err != nil {
return fmt.Errorf("Failed to add %v to VLAN interface %q", vlan.IPv6Addr, name)
}
}
if iface.Flags&net.FlagUp == 0 {
return nil
}
return ifaceUp(vlanIface)
} | [
"func",
"ifaceAddVLAN",
"(",
"iface",
"*",
"net",
".",
"Interface",
",",
"vlan",
"*",
"seesaw",
".",
"VLAN",
")",
"error",
"{",
"name",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"iface",
".",
"Name",
",",
"vlan",
".",
"ID",
")",
"\n",
"err",
":=",
"ipRunIface",
"(",
"iface",
",",
"\"",
"\"",
",",
"iface",
".",
"Name",
",",
"name",
",",
"vlan",
".",
"ID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"name",
",",
"err",
")",
"\n",
"}",
"\n\n",
"vlanIface",
",",
"err",
":=",
"net",
".",
"InterfaceByName",
"(",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"name",
",",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"sysctlInitIface",
"(",
"vlanIface",
".",
"Name",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"name",
",",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"vlan",
".",
"IPv4Addr",
"!=",
"nil",
"{",
"if",
"err",
":=",
"ifaceAddIPv4Addr",
"(",
"vlanIface",
",",
"vlan",
".",
"IPv4Addr",
",",
"vlan",
".",
"IPv4Mask",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"vlan",
".",
"IPv4Addr",
",",
"name",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"vlan",
".",
"IPv6Addr",
"!=",
"nil",
"{",
"if",
"err",
":=",
"ifaceAddIPv6Addr",
"(",
"vlanIface",
",",
"vlan",
".",
"IPv6Addr",
",",
"vlan",
".",
"IPv6Mask",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"vlan",
".",
"IPv6Addr",
",",
"name",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"iface",
".",
"Flags",
"&",
"net",
".",
"FlagUp",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"ifaceUp",
"(",
"vlanIface",
")",
"\n",
"}"
] | // ifaceAddVLAN creates a new VLAN interface on the given physical interface. | [
"ifaceAddVLAN",
"creates",
"a",
"new",
"VLAN",
"interface",
"on",
"the",
"given",
"physical",
"interface",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/ip.go#L197-L228 | train |
google/seesaw | ncc/ip.go | ifaceDelVLAN | func ifaceDelVLAN(iface *net.Interface, vlan *seesaw.VLAN) error {
name := fmt.Sprintf("%s.%d", iface.Name, vlan.ID)
vlanIface, err := net.InterfaceByName(name)
if err != nil {
return fmt.Errorf("Failed to find VLAN interface %q: %v", name, err)
}
return ipRunIface(vlanIface, "link del dev %s", vlanIface.Name)
} | go | func ifaceDelVLAN(iface *net.Interface, vlan *seesaw.VLAN) error {
name := fmt.Sprintf("%s.%d", iface.Name, vlan.ID)
vlanIface, err := net.InterfaceByName(name)
if err != nil {
return fmt.Errorf("Failed to find VLAN interface %q: %v", name, err)
}
return ipRunIface(vlanIface, "link del dev %s", vlanIface.Name)
} | [
"func",
"ifaceDelVLAN",
"(",
"iface",
"*",
"net",
".",
"Interface",
",",
"vlan",
"*",
"seesaw",
".",
"VLAN",
")",
"error",
"{",
"name",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"iface",
".",
"Name",
",",
"vlan",
".",
"ID",
")",
"\n",
"vlanIface",
",",
"err",
":=",
"net",
".",
"InterfaceByName",
"(",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"name",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"ipRunIface",
"(",
"vlanIface",
",",
"\"",
"\"",
",",
"vlanIface",
".",
"Name",
")",
"\n",
"}"
] | // ifaceDelVLAN removes a VLAN interface from the given physical interface. | [
"ifaceDelVLAN",
"removes",
"a",
"VLAN",
"interface",
"from",
"the",
"given",
"physical",
"interface",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/ip.go#L231-L238 | train |
google/seesaw | ncc/ip.go | ifaceFlushVLANs | func ifaceFlushVLANs(iface *net.Interface) error {
if err := validateInterface(iface); err != nil {
return err
}
vlanIfaces, err := vlanInterfaces(iface)
if err != nil {
return err
}
for _, vlanIface := range vlanIfaces {
if err := ipRunIface(vlanIface, "link del dev %s", vlanIface.Name); err != nil {
return fmt.Errorf("Failed to remove %s from %s: %v", vlanIface.Name, iface.Name, err)
}
}
return nil
} | go | func ifaceFlushVLANs(iface *net.Interface) error {
if err := validateInterface(iface); err != nil {
return err
}
vlanIfaces, err := vlanInterfaces(iface)
if err != nil {
return err
}
for _, vlanIface := range vlanIfaces {
if err := ipRunIface(vlanIface, "link del dev %s", vlanIface.Name); err != nil {
return fmt.Errorf("Failed to remove %s from %s: %v", vlanIface.Name, iface.Name, err)
}
}
return nil
} | [
"func",
"ifaceFlushVLANs",
"(",
"iface",
"*",
"net",
".",
"Interface",
")",
"error",
"{",
"if",
"err",
":=",
"validateInterface",
"(",
"iface",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"vlanIfaces",
",",
"err",
":=",
"vlanInterfaces",
"(",
"iface",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"for",
"_",
",",
"vlanIface",
":=",
"range",
"vlanIfaces",
"{",
"if",
"err",
":=",
"ipRunIface",
"(",
"vlanIface",
",",
"\"",
"\"",
",",
"vlanIface",
".",
"Name",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"vlanIface",
".",
"Name",
",",
"iface",
".",
"Name",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // ifaceFlushVLANs removes all VLAN interfaces from the given physical
// interface. | [
"ifaceFlushVLANs",
"removes",
"all",
"VLAN",
"interfaces",
"from",
"the",
"given",
"physical",
"interface",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/ip.go#L242-L256 | train |
google/seesaw | ncc/ip.go | routeDefaultIPv4 | func routeDefaultIPv4() (net.IP, error) {
out, err := ipRunAFOutput(seesaw.IPv4, "route show default")
if err != nil {
return nil, err
}
if dr := routeDefaultIPv4Regexp.FindStringSubmatch(out); dr != nil {
return net.ParseIP(dr[1]).To4(), nil
}
return nil, fmt.Errorf("Default route not found")
} | go | func routeDefaultIPv4() (net.IP, error) {
out, err := ipRunAFOutput(seesaw.IPv4, "route show default")
if err != nil {
return nil, err
}
if dr := routeDefaultIPv4Regexp.FindStringSubmatch(out); dr != nil {
return net.ParseIP(dr[1]).To4(), nil
}
return nil, fmt.Errorf("Default route not found")
} | [
"func",
"routeDefaultIPv4",
"(",
")",
"(",
"net",
".",
"IP",
",",
"error",
")",
"{",
"out",
",",
"err",
":=",
"ipRunAFOutput",
"(",
"seesaw",
".",
"IPv4",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"dr",
":=",
"routeDefaultIPv4Regexp",
".",
"FindStringSubmatch",
"(",
"out",
")",
";",
"dr",
"!=",
"nil",
"{",
"return",
"net",
".",
"ParseIP",
"(",
"dr",
"[",
"1",
"]",
")",
".",
"To4",
"(",
")",
",",
"nil",
"\n",
"}",
"\n",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}"
] | // routeDefaultIPv4 returns the default route for IPv4 traffic. | [
"routeDefaultIPv4",
"returns",
"the",
"default",
"route",
"for",
"IPv4",
"traffic",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/ip.go#L259-L268 | train |
google/seesaw | ncc/ip.go | removeRoutes | func removeRoutes(table string, vip net.IP) error {
af := seesaw.IPv6
if vip.To4() != nil {
af = seesaw.IPv4
}
return ipRunAF(af, "route flush table %s %s", table, vip)
} | go | func removeRoutes(table string, vip net.IP) error {
af := seesaw.IPv6
if vip.To4() != nil {
af = seesaw.IPv4
}
return ipRunAF(af, "route flush table %s %s", table, vip)
} | [
"func",
"removeRoutes",
"(",
"table",
"string",
",",
"vip",
"net",
".",
"IP",
")",
"error",
"{",
"af",
":=",
"seesaw",
".",
"IPv6",
"\n",
"if",
"vip",
".",
"To4",
"(",
")",
"!=",
"nil",
"{",
"af",
"=",
"seesaw",
".",
"IPv4",
"\n",
"}",
"\n",
"return",
"ipRunAF",
"(",
"af",
",",
"\"",
"\"",
",",
"table",
",",
"vip",
")",
"\n",
"}"
] | // removeRoutes deletes the routing table entries for a VIP, from the specified
// table. | [
"removeRoutes",
"deletes",
"the",
"routing",
"table",
"entries",
"for",
"a",
"VIP",
"from",
"the",
"specified",
"table",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/ip.go#L272-L278 | train |
google/seesaw | ncc/ip.go | routeLocal | func routeLocal(iface *net.Interface, vip net.IP, node seesaw.Host) error {
af := seesaw.IPv6
src := node.IPv6Addr
if vip.To4() != nil {
af = seesaw.IPv4
src = node.IPv4Addr
}
if err := removeLocalRoutes(vip); err != nil {
return err
}
return ipRunAF(af, "route add table local local %s dev %s src %s", vip, iface.Name, src)
} | go | func routeLocal(iface *net.Interface, vip net.IP, node seesaw.Host) error {
af := seesaw.IPv6
src := node.IPv6Addr
if vip.To4() != nil {
af = seesaw.IPv4
src = node.IPv4Addr
}
if err := removeLocalRoutes(vip); err != nil {
return err
}
return ipRunAF(af, "route add table local local %s dev %s src %s", vip, iface.Name, src)
} | [
"func",
"routeLocal",
"(",
"iface",
"*",
"net",
".",
"Interface",
",",
"vip",
"net",
".",
"IP",
",",
"node",
"seesaw",
".",
"Host",
")",
"error",
"{",
"af",
":=",
"seesaw",
".",
"IPv6",
"\n",
"src",
":=",
"node",
".",
"IPv6Addr",
"\n",
"if",
"vip",
".",
"To4",
"(",
")",
"!=",
"nil",
"{",
"af",
"=",
"seesaw",
".",
"IPv4",
"\n",
"src",
"=",
"node",
".",
"IPv4Addr",
"\n",
"}",
"\n",
"if",
"err",
":=",
"removeLocalRoutes",
"(",
"vip",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"ipRunAF",
"(",
"af",
",",
"\"",
"\"",
",",
"vip",
",",
"iface",
".",
"Name",
",",
"src",
")",
"\n",
"}"
] | // routeLocal removes all routes in the local routing table for the given VIP
// and adds new routes with the correct source address. | [
"routeLocal",
"removes",
"all",
"routes",
"in",
"the",
"local",
"routing",
"table",
"for",
"the",
"given",
"VIP",
"and",
"adds",
"new",
"routes",
"with",
"the",
"correct",
"source",
"address",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/ip.go#L292-L303 | train |
google/seesaw | ncc/ip.go | RouteDefaultIPv4 | func (ncc *SeesawNCC) RouteDefaultIPv4(unused int, gateway *net.IP) error {
ip, err := routeDefaultIPv4()
if err != nil {
return err
}
if gateway != nil {
*gateway = make(net.IP, len(ip))
copy(*gateway, ip)
}
return nil
} | go | func (ncc *SeesawNCC) RouteDefaultIPv4(unused int, gateway *net.IP) error {
ip, err := routeDefaultIPv4()
if err != nil {
return err
}
if gateway != nil {
*gateway = make(net.IP, len(ip))
copy(*gateway, ip)
}
return nil
} | [
"func",
"(",
"ncc",
"*",
"SeesawNCC",
")",
"RouteDefaultIPv4",
"(",
"unused",
"int",
",",
"gateway",
"*",
"net",
".",
"IP",
")",
"error",
"{",
"ip",
",",
"err",
":=",
"routeDefaultIPv4",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"gateway",
"!=",
"nil",
"{",
"*",
"gateway",
"=",
"make",
"(",
"net",
".",
"IP",
",",
"len",
"(",
"ip",
")",
")",
"\n",
"copy",
"(",
"*",
"gateway",
",",
"ip",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // RouteDefaultIPv4 returns the default route for IPv4 traffic. | [
"RouteDefaultIPv4",
"returns",
"the",
"default",
"route",
"for",
"IPv4",
"traffic",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/ip.go#L306-L316 | train |
google/seesaw | ncc/lb.go | addClusterVIP | func addClusterVIP(iface *ncctypes.LBInterface, netIface, nodeIface *net.Interface, clusterVIP net.IP) error {
nodeIP := iface.Node.IPv4Addr
family := seesaw.IPv4
if clusterVIP.To4() == nil {
nodeIP = iface.Node.IPv6Addr
family = seesaw.IPv6
}
if nodeIP == nil {
return fmt.Errorf("Node does not have an %s address", family)
}
log.Infof("Adding %s cluster VIP %s on %s", family, clusterVIP, iface.Name)
// Determine network for the node IP and ensure that the cluster VIP is
// contained within this network.
nodeNet, err := findNetwork(nodeIface, nodeIP)
if err != nil {
return fmt.Errorf("Failed to get node network: %v", err)
}
if !nodeNet.Contains(clusterVIP) {
return fmt.Errorf("Node network %s does not contain cluster VIP %s", nodeNet, clusterVIP)
}
// Set up routing policy for IPv4. These rules and the associated routes
// added in LBInterfaceUp tell the seesaw to:
// 1) Respond to ARP requests for the seesaw VIP
// 2) Send seesaw VIP reply traffic out eth1
//
// For IPv6, policy routing won't work on physical machines until
// b/10061534 is resolved. VIP reply traffic will go out eth0 which is fine,
// and neighbor discovery for the seesaw VIP works fine without policy routing
// anyway.
//
// TODO(angusc): Figure out how whether we can get rid of this.
if family == seesaw.IPv4 {
ipRunAF(family, "rule del to %s", clusterVIP)
ipRunAF(family, "rule del from %s", clusterVIP)
if err := ipRunAF(family, "rule add from all to %s lookup %d", clusterVIP, iface.RoutingTableID); err != nil {
return fmt.Errorf("Failed to set up routing policy: %v", err)
}
if err := ipRunAF(family, "rule add from %s lookup %d", clusterVIP, iface.RoutingTableID); err != nil {
return fmt.Errorf("Failed to set up routing policy: %v", err)
}
}
// Add cluster VIP to interface.
if err := ifaceAddIPAddr(netIface, clusterVIP, nodeNet.Mask); err != nil {
return fmt.Errorf("Failed to add cluster VIP to interface: %v", err)
}
return nil
} | go | func addClusterVIP(iface *ncctypes.LBInterface, netIface, nodeIface *net.Interface, clusterVIP net.IP) error {
nodeIP := iface.Node.IPv4Addr
family := seesaw.IPv4
if clusterVIP.To4() == nil {
nodeIP = iface.Node.IPv6Addr
family = seesaw.IPv6
}
if nodeIP == nil {
return fmt.Errorf("Node does not have an %s address", family)
}
log.Infof("Adding %s cluster VIP %s on %s", family, clusterVIP, iface.Name)
// Determine network for the node IP and ensure that the cluster VIP is
// contained within this network.
nodeNet, err := findNetwork(nodeIface, nodeIP)
if err != nil {
return fmt.Errorf("Failed to get node network: %v", err)
}
if !nodeNet.Contains(clusterVIP) {
return fmt.Errorf("Node network %s does not contain cluster VIP %s", nodeNet, clusterVIP)
}
// Set up routing policy for IPv4. These rules and the associated routes
// added in LBInterfaceUp tell the seesaw to:
// 1) Respond to ARP requests for the seesaw VIP
// 2) Send seesaw VIP reply traffic out eth1
//
// For IPv6, policy routing won't work on physical machines until
// b/10061534 is resolved. VIP reply traffic will go out eth0 which is fine,
// and neighbor discovery for the seesaw VIP works fine without policy routing
// anyway.
//
// TODO(angusc): Figure out how whether we can get rid of this.
if family == seesaw.IPv4 {
ipRunAF(family, "rule del to %s", clusterVIP)
ipRunAF(family, "rule del from %s", clusterVIP)
if err := ipRunAF(family, "rule add from all to %s lookup %d", clusterVIP, iface.RoutingTableID); err != nil {
return fmt.Errorf("Failed to set up routing policy: %v", err)
}
if err := ipRunAF(family, "rule add from %s lookup %d", clusterVIP, iface.RoutingTableID); err != nil {
return fmt.Errorf("Failed to set up routing policy: %v", err)
}
}
// Add cluster VIP to interface.
if err := ifaceAddIPAddr(netIface, clusterVIP, nodeNet.Mask); err != nil {
return fmt.Errorf("Failed to add cluster VIP to interface: %v", err)
}
return nil
} | [
"func",
"addClusterVIP",
"(",
"iface",
"*",
"ncctypes",
".",
"LBInterface",
",",
"netIface",
",",
"nodeIface",
"*",
"net",
".",
"Interface",
",",
"clusterVIP",
"net",
".",
"IP",
")",
"error",
"{",
"nodeIP",
":=",
"iface",
".",
"Node",
".",
"IPv4Addr",
"\n",
"family",
":=",
"seesaw",
".",
"IPv4",
"\n",
"if",
"clusterVIP",
".",
"To4",
"(",
")",
"==",
"nil",
"{",
"nodeIP",
"=",
"iface",
".",
"Node",
".",
"IPv6Addr",
"\n",
"family",
"=",
"seesaw",
".",
"IPv6",
"\n",
"}",
"\n",
"if",
"nodeIP",
"==",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"family",
")",
"\n",
"}",
"\n\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"family",
",",
"clusterVIP",
",",
"iface",
".",
"Name",
")",
"\n\n",
"// Determine network for the node IP and ensure that the cluster VIP is",
"// contained within this network.",
"nodeNet",
",",
"err",
":=",
"findNetwork",
"(",
"nodeIface",
",",
"nodeIP",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"!",
"nodeNet",
".",
"Contains",
"(",
"clusterVIP",
")",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"nodeNet",
",",
"clusterVIP",
")",
"\n",
"}",
"\n\n",
"// Set up routing policy for IPv4. These rules and the associated routes",
"// added in LBInterfaceUp tell the seesaw to:",
"// 1) Respond to ARP requests for the seesaw VIP",
"// 2) Send seesaw VIP reply traffic out eth1",
"//",
"// For IPv6, policy routing won't work on physical machines until",
"// b/10061534 is resolved. VIP reply traffic will go out eth0 which is fine,",
"// and neighbor discovery for the seesaw VIP works fine without policy routing",
"// anyway.",
"//",
"// TODO(angusc): Figure out how whether we can get rid of this.",
"if",
"family",
"==",
"seesaw",
".",
"IPv4",
"{",
"ipRunAF",
"(",
"family",
",",
"\"",
"\"",
",",
"clusterVIP",
")",
"\n",
"ipRunAF",
"(",
"family",
",",
"\"",
"\"",
",",
"clusterVIP",
")",
"\n",
"if",
"err",
":=",
"ipRunAF",
"(",
"family",
",",
"\"",
"\"",
",",
"clusterVIP",
",",
"iface",
".",
"RoutingTableID",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"ipRunAF",
"(",
"family",
",",
"\"",
"\"",
",",
"clusterVIP",
",",
"iface",
".",
"RoutingTableID",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Add cluster VIP to interface.",
"if",
"err",
":=",
"ifaceAddIPAddr",
"(",
"netIface",
",",
"clusterVIP",
",",
"nodeNet",
".",
"Mask",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // addClusterVIP adds a cluster VIP to the load balancing interface and
// performs additional network configuration. | [
"addClusterVIP",
"adds",
"a",
"cluster",
"VIP",
"to",
"the",
"load",
"balancing",
"interface",
"and",
"performs",
"additional",
"network",
"configuration",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/lb.go#L120-L171 | train |
google/seesaw | ncc/lb.go | LBInterfaceDown | func (ncc *SeesawNCC) LBInterfaceDown(iface *ncctypes.LBInterface, out *int) error {
netIface, err := iface.Interface()
if err != nil {
return err
}
log.Infof("Bringing down LB interface %s", netIface.Name)
return ifaceDown(netIface)
} | go | func (ncc *SeesawNCC) LBInterfaceDown(iface *ncctypes.LBInterface, out *int) error {
netIface, err := iface.Interface()
if err != nil {
return err
}
log.Infof("Bringing down LB interface %s", netIface.Name)
return ifaceDown(netIface)
} | [
"func",
"(",
"ncc",
"*",
"SeesawNCC",
")",
"LBInterfaceDown",
"(",
"iface",
"*",
"ncctypes",
".",
"LBInterface",
",",
"out",
"*",
"int",
")",
"error",
"{",
"netIface",
",",
"err",
":=",
"iface",
".",
"Interface",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"netIface",
".",
"Name",
")",
"\n",
"return",
"ifaceDown",
"(",
"netIface",
")",
"\n",
"}"
] | // LBInterfaceDown brings the load balancing interface down. | [
"LBInterfaceDown",
"brings",
"the",
"load",
"balancing",
"interface",
"down",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/lb.go#L174-L181 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.