id
int32
0
167k
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
listlengths
21
1.41k
docstring
stringlengths
6
2.61k
docstring_tokens
listlengths
3
215
sha
stringlengths
40
40
url
stringlengths
85
252
22,600
docker/libnetwork
network.go
MarshalJSON
func (i *IpamInfo) MarshalJSON() ([]byte, error) { m := map[string]interface{}{ "PoolID": i.PoolID, } v, err := json.Marshal(&i.IPAMData) if err != nil { return nil, err } m["IPAMData"] = string(v) if i.Meta != nil { m["Meta"] = i.Meta } return json.Marshal(m) }
go
func (i *IpamInfo) MarshalJSON() ([]byte, error) { m := map[string]interface{}{ "PoolID": i.PoolID, } v, err := json.Marshal(&i.IPAMData) if err != nil { return nil, err } m["IPAMData"] = string(v) if i.Meta != nil { m["Meta"] = i.Meta } return json.Marshal(m) }
[ "func", "(", "i", "*", "IpamInfo", ")", "MarshalJSON", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "m", ":=", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "i", ".", "PoolID", ",", "}", "\n", "v", ",", "err", ":=", "json", ".", "Marshal", "(", "&", "i", ".", "IPAMData", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "m", "[", "\"", "\"", "]", "=", "string", "(", "v", ")", "\n\n", "if", "i", ".", "Meta", "!=", "nil", "{", "m", "[", "\"", "\"", "]", "=", "i", ".", "Meta", "\n", "}", "\n", "return", "json", ".", "Marshal", "(", "m", ")", "\n", "}" ]
// MarshalJSON encodes IpamInfo into json message
[ "MarshalJSON", "encodes", "IpamInfo", "into", "json", "message" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/network.go#L161-L175
22,601
docker/libnetwork
network.go
UnmarshalJSON
func (i *IpamInfo) UnmarshalJSON(data []byte) error { var ( m map[string]interface{} err error ) if err = json.Unmarshal(data, &m); err != nil { return err } i.PoolID = m["PoolID"].(string) if v, ok := m["Meta"]; ok { b, _ := json.Marshal(v) if err = json.Unmarshal(b, &i.Meta); err != nil { return err } } if v, ok := m["IPAMData"]; ok { if err = json.Unmarshal([]byte(v.(string)), &i.IPAMData); err != nil { return err } } return nil }
go
func (i *IpamInfo) UnmarshalJSON(data []byte) error { var ( m map[string]interface{} err error ) if err = json.Unmarshal(data, &m); err != nil { return err } i.PoolID = m["PoolID"].(string) if v, ok := m["Meta"]; ok { b, _ := json.Marshal(v) if err = json.Unmarshal(b, &i.Meta); err != nil { return err } } if v, ok := m["IPAMData"]; ok { if err = json.Unmarshal([]byte(v.(string)), &i.IPAMData); err != nil { return err } } return nil }
[ "func", "(", "i", "*", "IpamInfo", ")", "UnmarshalJSON", "(", "data", "[", "]", "byte", ")", "error", "{", "var", "(", "m", "map", "[", "string", "]", "interface", "{", "}", "\n", "err", "error", "\n", ")", "\n", "if", "err", "=", "json", ".", "Unmarshal", "(", "data", ",", "&", "m", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "i", ".", "PoolID", "=", "m", "[", "\"", "\"", "]", ".", "(", "string", ")", "\n", "if", "v", ",", "ok", ":=", "m", "[", "\"", "\"", "]", ";", "ok", "{", "b", ",", "_", ":=", "json", ".", "Marshal", "(", "v", ")", "\n", "if", "err", "=", "json", ".", "Unmarshal", "(", "b", ",", "&", "i", ".", "Meta", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "if", "v", ",", "ok", ":=", "m", "[", "\"", "\"", "]", ";", "ok", "{", "if", "err", "=", "json", ".", "Unmarshal", "(", "[", "]", "byte", "(", "v", ".", "(", "string", ")", ")", ",", "&", "i", ".", "IPAMData", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// UnmarshalJSON decodes json message into PoolData
[ "UnmarshalJSON", "decodes", "json", "message", "into", "PoolData" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/network.go#L178-L199
22,602
docker/libnetwork
network.go
CopyTo
func (c *IpamConf) CopyTo(dstC *IpamConf) error { dstC.PreferredPool = c.PreferredPool dstC.SubPool = c.SubPool dstC.Gateway = c.Gateway if c.AuxAddresses != nil { dstC.AuxAddresses = make(map[string]string, len(c.AuxAddresses)) for k, v := range c.AuxAddresses { dstC.AuxAddresses[k] = v } } return nil }
go
func (c *IpamConf) CopyTo(dstC *IpamConf) error { dstC.PreferredPool = c.PreferredPool dstC.SubPool = c.SubPool dstC.Gateway = c.Gateway if c.AuxAddresses != nil { dstC.AuxAddresses = make(map[string]string, len(c.AuxAddresses)) for k, v := range c.AuxAddresses { dstC.AuxAddresses[k] = v } } return nil }
[ "func", "(", "c", "*", "IpamConf", ")", "CopyTo", "(", "dstC", "*", "IpamConf", ")", "error", "{", "dstC", ".", "PreferredPool", "=", "c", ".", "PreferredPool", "\n", "dstC", ".", "SubPool", "=", "c", ".", "SubPool", "\n", "dstC", ".", "Gateway", "=", "c", ".", "Gateway", "\n", "if", "c", ".", "AuxAddresses", "!=", "nil", "{", "dstC", ".", "AuxAddresses", "=", "make", "(", "map", "[", "string", "]", "string", ",", "len", "(", "c", ".", "AuxAddresses", ")", ")", "\n", "for", "k", ",", "v", ":=", "range", "c", ".", "AuxAddresses", "{", "dstC", ".", "AuxAddresses", "[", "k", "]", "=", "v", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// CopyTo deep copies to the destination IpamConfig
[ "CopyTo", "deep", "copies", "to", "the", "destination", "IpamConfig" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/network.go#L335-L346
22,603
docker/libnetwork
network.go
CopyTo
func (i *IpamInfo) CopyTo(dstI *IpamInfo) error { dstI.PoolID = i.PoolID if i.Meta != nil { dstI.Meta = make(map[string]string) for k, v := range i.Meta { dstI.Meta[k] = v } } dstI.AddressSpace = i.AddressSpace dstI.Pool = types.GetIPNetCopy(i.Pool) dstI.Gateway = types.GetIPNetCopy(i.Gateway) if i.AuxAddresses != nil { dstI.AuxAddresses = make(map[string]*net.IPNet) for k, v := range i.AuxAddresses { dstI.AuxAddresses[k] = types.GetIPNetCopy(v) } } return nil }
go
func (i *IpamInfo) CopyTo(dstI *IpamInfo) error { dstI.PoolID = i.PoolID if i.Meta != nil { dstI.Meta = make(map[string]string) for k, v := range i.Meta { dstI.Meta[k] = v } } dstI.AddressSpace = i.AddressSpace dstI.Pool = types.GetIPNetCopy(i.Pool) dstI.Gateway = types.GetIPNetCopy(i.Gateway) if i.AuxAddresses != nil { dstI.AuxAddresses = make(map[string]*net.IPNet) for k, v := range i.AuxAddresses { dstI.AuxAddresses[k] = types.GetIPNetCopy(v) } } return nil }
[ "func", "(", "i", "*", "IpamInfo", ")", "CopyTo", "(", "dstI", "*", "IpamInfo", ")", "error", "{", "dstI", ".", "PoolID", "=", "i", ".", "PoolID", "\n", "if", "i", ".", "Meta", "!=", "nil", "{", "dstI", ".", "Meta", "=", "make", "(", "map", "[", "string", "]", "string", ")", "\n", "for", "k", ",", "v", ":=", "range", "i", ".", "Meta", "{", "dstI", ".", "Meta", "[", "k", "]", "=", "v", "\n", "}", "\n", "}", "\n\n", "dstI", ".", "AddressSpace", "=", "i", ".", "AddressSpace", "\n", "dstI", ".", "Pool", "=", "types", ".", "GetIPNetCopy", "(", "i", ".", "Pool", ")", "\n", "dstI", ".", "Gateway", "=", "types", ".", "GetIPNetCopy", "(", "i", ".", "Gateway", ")", "\n\n", "if", "i", ".", "AuxAddresses", "!=", "nil", "{", "dstI", ".", "AuxAddresses", "=", "make", "(", "map", "[", "string", "]", "*", "net", ".", "IPNet", ")", "\n", "for", "k", ",", "v", ":=", "range", "i", ".", "AuxAddresses", "{", "dstI", ".", "AuxAddresses", "[", "k", "]", "=", "types", ".", "GetIPNetCopy", "(", "v", ")", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// CopyTo deep copies to the destination IpamInfo
[ "CopyTo", "deep", "copies", "to", "the", "destination", "IpamInfo" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/network.go#L349-L370
22,604
docker/libnetwork
network.go
applyConfigurationTo
func (n *network) applyConfigurationTo(to *network) error { to.enableIPv6 = n.enableIPv6 if len(n.labels) > 0 { to.labels = make(map[string]string, len(n.labels)) for k, v := range n.labels { if _, ok := to.labels[k]; !ok { to.labels[k] = v } } } if len(n.ipamType) != 0 { to.ipamType = n.ipamType } if len(n.ipamOptions) > 0 { to.ipamOptions = make(map[string]string, len(n.ipamOptions)) for k, v := range n.ipamOptions { if _, ok := to.ipamOptions[k]; !ok { to.ipamOptions[k] = v } } } if len(n.ipamV4Config) > 0 { to.ipamV4Config = make([]*IpamConf, 0, len(n.ipamV4Config)) to.ipamV4Config = append(to.ipamV4Config, n.ipamV4Config...) } if len(n.ipamV6Config) > 0 { to.ipamV6Config = make([]*IpamConf, 0, len(n.ipamV6Config)) to.ipamV6Config = append(to.ipamV6Config, n.ipamV6Config...) } if len(n.generic) > 0 { to.generic = options.Generic{} for k, v := range n.generic { to.generic[k] = v } } return nil }
go
func (n *network) applyConfigurationTo(to *network) error { to.enableIPv6 = n.enableIPv6 if len(n.labels) > 0 { to.labels = make(map[string]string, len(n.labels)) for k, v := range n.labels { if _, ok := to.labels[k]; !ok { to.labels[k] = v } } } if len(n.ipamType) != 0 { to.ipamType = n.ipamType } if len(n.ipamOptions) > 0 { to.ipamOptions = make(map[string]string, len(n.ipamOptions)) for k, v := range n.ipamOptions { if _, ok := to.ipamOptions[k]; !ok { to.ipamOptions[k] = v } } } if len(n.ipamV4Config) > 0 { to.ipamV4Config = make([]*IpamConf, 0, len(n.ipamV4Config)) to.ipamV4Config = append(to.ipamV4Config, n.ipamV4Config...) } if len(n.ipamV6Config) > 0 { to.ipamV6Config = make([]*IpamConf, 0, len(n.ipamV6Config)) to.ipamV6Config = append(to.ipamV6Config, n.ipamV6Config...) } if len(n.generic) > 0 { to.generic = options.Generic{} for k, v := range n.generic { to.generic[k] = v } } return nil }
[ "func", "(", "n", "*", "network", ")", "applyConfigurationTo", "(", "to", "*", "network", ")", "error", "{", "to", ".", "enableIPv6", "=", "n", ".", "enableIPv6", "\n", "if", "len", "(", "n", ".", "labels", ")", ">", "0", "{", "to", ".", "labels", "=", "make", "(", "map", "[", "string", "]", "string", ",", "len", "(", "n", ".", "labels", ")", ")", "\n", "for", "k", ",", "v", ":=", "range", "n", ".", "labels", "{", "if", "_", ",", "ok", ":=", "to", ".", "labels", "[", "k", "]", ";", "!", "ok", "{", "to", ".", "labels", "[", "k", "]", "=", "v", "\n", "}", "\n", "}", "\n", "}", "\n", "if", "len", "(", "n", ".", "ipamType", ")", "!=", "0", "{", "to", ".", "ipamType", "=", "n", ".", "ipamType", "\n", "}", "\n", "if", "len", "(", "n", ".", "ipamOptions", ")", ">", "0", "{", "to", ".", "ipamOptions", "=", "make", "(", "map", "[", "string", "]", "string", ",", "len", "(", "n", ".", "ipamOptions", ")", ")", "\n", "for", "k", ",", "v", ":=", "range", "n", ".", "ipamOptions", "{", "if", "_", ",", "ok", ":=", "to", ".", "ipamOptions", "[", "k", "]", ";", "!", "ok", "{", "to", ".", "ipamOptions", "[", "k", "]", "=", "v", "\n", "}", "\n", "}", "\n", "}", "\n", "if", "len", "(", "n", ".", "ipamV4Config", ")", ">", "0", "{", "to", ".", "ipamV4Config", "=", "make", "(", "[", "]", "*", "IpamConf", ",", "0", ",", "len", "(", "n", ".", "ipamV4Config", ")", ")", "\n", "to", ".", "ipamV4Config", "=", "append", "(", "to", ".", "ipamV4Config", ",", "n", ".", "ipamV4Config", "...", ")", "\n", "}", "\n", "if", "len", "(", "n", ".", "ipamV6Config", ")", ">", "0", "{", "to", ".", "ipamV6Config", "=", "make", "(", "[", "]", "*", "IpamConf", ",", "0", ",", "len", "(", "n", ".", "ipamV6Config", ")", ")", "\n", "to", ".", "ipamV6Config", "=", "append", "(", "to", ".", "ipamV6Config", ",", "n", ".", "ipamV6Config", "...", ")", "\n", "}", "\n", "if", "len", "(", "n", ".", "generic", ")", ">", "0", "{", "to", ".", "generic", "=", "options", ".", "Generic", "{", "}", "\n", "for", "k", ",", "v", ":=", "range", "n", ".", "generic", "{", "to", ".", "generic", "[", "k", "]", "=", "v", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Applies network specific configurations
[ "Applies", "network", "specific", "configurations" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/network.go#L420-L456
22,605
docker/libnetwork
network.go
NetworkOptionGeneric
func NetworkOptionGeneric(generic map[string]interface{}) NetworkOption { return func(n *network) { if n.generic == nil { n.generic = make(map[string]interface{}) } if val, ok := generic[netlabel.EnableIPv6]; ok { n.enableIPv6 = val.(bool) } if val, ok := generic[netlabel.Internal]; ok { n.internal = val.(bool) } for k, v := range generic { n.generic[k] = v } } }
go
func NetworkOptionGeneric(generic map[string]interface{}) NetworkOption { return func(n *network) { if n.generic == nil { n.generic = make(map[string]interface{}) } if val, ok := generic[netlabel.EnableIPv6]; ok { n.enableIPv6 = val.(bool) } if val, ok := generic[netlabel.Internal]; ok { n.internal = val.(bool) } for k, v := range generic { n.generic[k] = v } } }
[ "func", "NetworkOptionGeneric", "(", "generic", "map", "[", "string", "]", "interface", "{", "}", ")", "NetworkOption", "{", "return", "func", "(", "n", "*", "network", ")", "{", "if", "n", ".", "generic", "==", "nil", "{", "n", ".", "generic", "=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "}", "\n", "if", "val", ",", "ok", ":=", "generic", "[", "netlabel", ".", "EnableIPv6", "]", ";", "ok", "{", "n", ".", "enableIPv6", "=", "val", ".", "(", "bool", ")", "\n", "}", "\n", "if", "val", ",", "ok", ":=", "generic", "[", "netlabel", ".", "Internal", "]", ";", "ok", "{", "n", ".", "internal", "=", "val", ".", "(", "bool", ")", "\n", "}", "\n", "for", "k", ",", "v", ":=", "range", "generic", "{", "n", ".", "generic", "[", "k", "]", "=", "v", "\n", "}", "\n", "}", "\n", "}" ]
// NetworkOptionGeneric function returns an option setter for a Generic option defined // in a Dictionary of Key-Value pair
[ "NetworkOptionGeneric", "function", "returns", "an", "option", "setter", "for", "a", "Generic", "option", "defined", "in", "a", "Dictionary", "of", "Key", "-", "Value", "pair" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/network.go#L733-L748
22,606
docker/libnetwork
network.go
NetworkOptionEnableIPv6
func NetworkOptionEnableIPv6(enableIPv6 bool) NetworkOption { return func(n *network) { if n.generic == nil { n.generic = make(map[string]interface{}) } n.enableIPv6 = enableIPv6 n.generic[netlabel.EnableIPv6] = enableIPv6 } }
go
func NetworkOptionEnableIPv6(enableIPv6 bool) NetworkOption { return func(n *network) { if n.generic == nil { n.generic = make(map[string]interface{}) } n.enableIPv6 = enableIPv6 n.generic[netlabel.EnableIPv6] = enableIPv6 } }
[ "func", "NetworkOptionEnableIPv6", "(", "enableIPv6", "bool", ")", "NetworkOption", "{", "return", "func", "(", "n", "*", "network", ")", "{", "if", "n", ".", "generic", "==", "nil", "{", "n", ".", "generic", "=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "}", "\n", "n", ".", "enableIPv6", "=", "enableIPv6", "\n", "n", ".", "generic", "[", "netlabel", ".", "EnableIPv6", "]", "=", "enableIPv6", "\n", "}", "\n", "}" ]
// NetworkOptionEnableIPv6 returns an option setter to explicitly configure IPv6
[ "NetworkOptionEnableIPv6", "returns", "an", "option", "setter", "to", "explicitly", "configure", "IPv6" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/network.go#L766-L774
22,607
docker/libnetwork
network.go
NetworkOptionInternalNetwork
func NetworkOptionInternalNetwork() NetworkOption { return func(n *network) { if n.generic == nil { n.generic = make(map[string]interface{}) } n.internal = true n.generic[netlabel.Internal] = true } }
go
func NetworkOptionInternalNetwork() NetworkOption { return func(n *network) { if n.generic == nil { n.generic = make(map[string]interface{}) } n.internal = true n.generic[netlabel.Internal] = true } }
[ "func", "NetworkOptionInternalNetwork", "(", ")", "NetworkOption", "{", "return", "func", "(", "n", "*", "network", ")", "{", "if", "n", ".", "generic", "==", "nil", "{", "n", ".", "generic", "=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "}", "\n", "n", ".", "internal", "=", "true", "\n", "n", ".", "generic", "[", "netlabel", ".", "Internal", "]", "=", "true", "\n", "}", "\n", "}" ]
// NetworkOptionInternalNetwork returns an option setter to config the network // to be internal which disables default gateway service
[ "NetworkOptionInternalNetwork", "returns", "an", "option", "setter", "to", "config", "the", "network", "to", "be", "internal", "which", "disables", "default", "gateway", "service" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/network.go#L778-L786
22,608
docker/libnetwork
network.go
NetworkOptionIpam
func NetworkOptionIpam(ipamDriver string, addrSpace string, ipV4 []*IpamConf, ipV6 []*IpamConf, opts map[string]string) NetworkOption { return func(n *network) { if ipamDriver != "" { n.ipamType = ipamDriver if ipamDriver == ipamapi.DefaultIPAM { n.ipamType = defaultIpamForNetworkType(n.Type()) } } n.ipamOptions = opts n.addrSpace = addrSpace n.ipamV4Config = ipV4 n.ipamV6Config = ipV6 } }
go
func NetworkOptionIpam(ipamDriver string, addrSpace string, ipV4 []*IpamConf, ipV6 []*IpamConf, opts map[string]string) NetworkOption { return func(n *network) { if ipamDriver != "" { n.ipamType = ipamDriver if ipamDriver == ipamapi.DefaultIPAM { n.ipamType = defaultIpamForNetworkType(n.Type()) } } n.ipamOptions = opts n.addrSpace = addrSpace n.ipamV4Config = ipV4 n.ipamV6Config = ipV6 } }
[ "func", "NetworkOptionIpam", "(", "ipamDriver", "string", ",", "addrSpace", "string", ",", "ipV4", "[", "]", "*", "IpamConf", ",", "ipV6", "[", "]", "*", "IpamConf", ",", "opts", "map", "[", "string", "]", "string", ")", "NetworkOption", "{", "return", "func", "(", "n", "*", "network", ")", "{", "if", "ipamDriver", "!=", "\"", "\"", "{", "n", ".", "ipamType", "=", "ipamDriver", "\n", "if", "ipamDriver", "==", "ipamapi", ".", "DefaultIPAM", "{", "n", ".", "ipamType", "=", "defaultIpamForNetworkType", "(", "n", ".", "Type", "(", ")", ")", "\n", "}", "\n", "}", "\n", "n", ".", "ipamOptions", "=", "opts", "\n", "n", ".", "addrSpace", "=", "addrSpace", "\n", "n", ".", "ipamV4Config", "=", "ipV4", "\n", "n", ".", "ipamV6Config", "=", "ipV6", "\n", "}", "\n", "}" ]
// NetworkOptionIpam function returns an option setter for the ipam configuration for this network
[ "NetworkOptionIpam", "function", "returns", "an", "option", "setter", "for", "the", "ipam", "configuration", "for", "this", "network" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/network.go#L804-L817
22,609
docker/libnetwork
network.go
NetworkOptionLBEndpoint
func NetworkOptionLBEndpoint(ip net.IP) NetworkOption { return func(n *network) { n.loadBalancerIP = ip } }
go
func NetworkOptionLBEndpoint(ip net.IP) NetworkOption { return func(n *network) { n.loadBalancerIP = ip } }
[ "func", "NetworkOptionLBEndpoint", "(", "ip", "net", ".", "IP", ")", "NetworkOption", "{", "return", "func", "(", "n", "*", "network", ")", "{", "n", ".", "loadBalancerIP", "=", "ip", "\n", "}", "\n", "}" ]
// NetworkOptionLBEndpoint function returns an option setter for the configuration of the load balancer endpoint for this network
[ "NetworkOptionLBEndpoint", "function", "returns", "an", "option", "setter", "for", "the", "configuration", "of", "the", "load", "balancer", "endpoint", "for", "this", "network" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/network.go#L820-L824
22,610
docker/libnetwork
network.go
NetworkOptionDriverOpts
func NetworkOptionDriverOpts(opts map[string]string) NetworkOption { return func(n *network) { if n.generic == nil { n.generic = make(map[string]interface{}) } if opts == nil { opts = make(map[string]string) } // Store the options n.generic[netlabel.GenericData] = opts } }
go
func NetworkOptionDriverOpts(opts map[string]string) NetworkOption { return func(n *network) { if n.generic == nil { n.generic = make(map[string]interface{}) } if opts == nil { opts = make(map[string]string) } // Store the options n.generic[netlabel.GenericData] = opts } }
[ "func", "NetworkOptionDriverOpts", "(", "opts", "map", "[", "string", "]", "string", ")", "NetworkOption", "{", "return", "func", "(", "n", "*", "network", ")", "{", "if", "n", ".", "generic", "==", "nil", "{", "n", ".", "generic", "=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "}", "\n", "if", "opts", "==", "nil", "{", "opts", "=", "make", "(", "map", "[", "string", "]", "string", ")", "\n", "}", "\n", "// Store the options", "n", ".", "generic", "[", "netlabel", ".", "GenericData", "]", "=", "opts", "\n", "}", "\n", "}" ]
// NetworkOptionDriverOpts function returns an option setter for any driver parameter described by a map
[ "NetworkOptionDriverOpts", "function", "returns", "an", "option", "setter", "for", "any", "driver", "parameter", "described", "by", "a", "map" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/network.go#L827-L838
22,611
docker/libnetwork
network.go
NetworkOptionLabels
func NetworkOptionLabels(labels map[string]string) NetworkOption { return func(n *network) { n.labels = labels } }
go
func NetworkOptionLabels(labels map[string]string) NetworkOption { return func(n *network) { n.labels = labels } }
[ "func", "NetworkOptionLabels", "(", "labels", "map", "[", "string", "]", "string", ")", "NetworkOption", "{", "return", "func", "(", "n", "*", "network", ")", "{", "n", ".", "labels", "=", "labels", "\n", "}", "\n", "}" ]
// NetworkOptionLabels function returns an option setter for labels specific to a network
[ "NetworkOptionLabels", "function", "returns", "an", "option", "setter", "for", "labels", "specific", "to", "a", "network" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/network.go#L841-L845
22,612
docker/libnetwork
network.go
getConfigNetwork
func (c *controller) getConfigNetwork(name string) (*network, error) { var n Network s := func(current Network) bool { if current.Info().ConfigOnly() && current.Name() == name { n = current return true } return false } c.WalkNetworks(s) if n == nil { return nil, types.NotFoundErrorf("configuration network %q not found", name) } return n.(*network), nil }
go
func (c *controller) getConfigNetwork(name string) (*network, error) { var n Network s := func(current Network) bool { if current.Info().ConfigOnly() && current.Name() == name { n = current return true } return false } c.WalkNetworks(s) if n == nil { return nil, types.NotFoundErrorf("configuration network %q not found", name) } return n.(*network), nil }
[ "func", "(", "c", "*", "controller", ")", "getConfigNetwork", "(", "name", "string", ")", "(", "*", "network", ",", "error", ")", "{", "var", "n", "Network", "\n\n", "s", ":=", "func", "(", "current", "Network", ")", "bool", "{", "if", "current", ".", "Info", "(", ")", ".", "ConfigOnly", "(", ")", "&&", "current", ".", "Name", "(", ")", "==", "name", "{", "n", "=", "current", "\n", "return", "true", "\n", "}", "\n", "return", "false", "\n", "}", "\n\n", "c", ".", "WalkNetworks", "(", "s", ")", "\n\n", "if", "n", "==", "nil", "{", "return", "nil", ",", "types", ".", "NotFoundErrorf", "(", "\"", "\"", ",", "name", ")", "\n", "}", "\n\n", "return", "n", ".", "(", "*", "network", ")", ",", "nil", "\n", "}" ]
// config-only network is looked up by name
[ "config", "-", "only", "network", "is", "looked", "up", "by", "name" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/network.go#L2105-L2123
22,613
docker/libnetwork
iptables/iptables.go
NewChain
func NewChain(name string, table Table, hairpinMode bool) (*ChainInfo, error) { c := &ChainInfo{ Name: name, Table: table, HairpinMode: hairpinMode, } if string(c.Table) == "" { c.Table = Filter } // Add chain if it doesn't exist if _, err := Raw("-t", string(c.Table), "-n", "-L", c.Name); err != nil { if output, err := Raw("-t", string(c.Table), "-N", c.Name); err != nil { return nil, err } else if len(output) != 0 { return nil, fmt.Errorf("Could not create %s/%s chain: %s", c.Table, c.Name, output) } } return c, nil }
go
func NewChain(name string, table Table, hairpinMode bool) (*ChainInfo, error) { c := &ChainInfo{ Name: name, Table: table, HairpinMode: hairpinMode, } if string(c.Table) == "" { c.Table = Filter } // Add chain if it doesn't exist if _, err := Raw("-t", string(c.Table), "-n", "-L", c.Name); err != nil { if output, err := Raw("-t", string(c.Table), "-N", c.Name); err != nil { return nil, err } else if len(output) != 0 { return nil, fmt.Errorf("Could not create %s/%s chain: %s", c.Table, c.Name, output) } } return c, nil }
[ "func", "NewChain", "(", "name", "string", ",", "table", "Table", ",", "hairpinMode", "bool", ")", "(", "*", "ChainInfo", ",", "error", ")", "{", "c", ":=", "&", "ChainInfo", "{", "Name", ":", "name", ",", "Table", ":", "table", ",", "HairpinMode", ":", "hairpinMode", ",", "}", "\n", "if", "string", "(", "c", ".", "Table", ")", "==", "\"", "\"", "{", "c", ".", "Table", "=", "Filter", "\n", "}", "\n\n", "// Add chain if it doesn't exist", "if", "_", ",", "err", ":=", "Raw", "(", "\"", "\"", ",", "string", "(", "c", ".", "Table", ")", ",", "\"", "\"", ",", "\"", "\"", ",", "c", ".", "Name", ")", ";", "err", "!=", "nil", "{", "if", "output", ",", "err", ":=", "Raw", "(", "\"", "\"", ",", "string", "(", "c", ".", "Table", ")", ",", "\"", "\"", ",", "c", ".", "Name", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "else", "if", "len", "(", "output", ")", "!=", "0", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "c", ".", "Table", ",", "c", ".", "Name", ",", "output", ")", "\n", "}", "\n", "}", "\n", "return", "c", ",", "nil", "\n", "}" ]
// NewChain adds a new chain to ip table.
[ "NewChain", "adds", "a", "new", "chain", "to", "ip", "table", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/iptables/iptables.go#L120-L139
22,614
docker/libnetwork
iptables/iptables.go
RemoveExistingChain
func RemoveExistingChain(name string, table Table) error { c := &ChainInfo{ Name: name, Table: table, } if string(c.Table) == "" { c.Table = Filter } return c.Remove() }
go
func RemoveExistingChain(name string, table Table) error { c := &ChainInfo{ Name: name, Table: table, } if string(c.Table) == "" { c.Table = Filter } return c.Remove() }
[ "func", "RemoveExistingChain", "(", "name", "string", ",", "table", "Table", ")", "error", "{", "c", ":=", "&", "ChainInfo", "{", "Name", ":", "name", ",", "Table", ":", "table", ",", "}", "\n", "if", "string", "(", "c", ".", "Table", ")", "==", "\"", "\"", "{", "c", ".", "Table", "=", "Filter", "\n", "}", "\n", "return", "c", ".", "Remove", "(", ")", "\n", "}" ]
// RemoveExistingChain removes existing chain from the table.
[ "RemoveExistingChain", "removes", "existing", "chain", "from", "the", "table", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/iptables/iptables.go#L227-L236
22,615
docker/libnetwork
iptables/iptables.go
Forward
func (c *ChainInfo) Forward(action Action, ip net.IP, port int, proto, destAddr string, destPort int, bridgeName string) error { daddr := ip.String() if ip.IsUnspecified() { // iptables interprets "0.0.0.0" as "0.0.0.0/32", whereas we // want "0.0.0.0/0". "0/0" is correctly interpreted as "any // value" by both iptables and ip6tables. daddr = "0/0" } args := []string{ "-p", proto, "-d", daddr, "--dport", strconv.Itoa(port), "-j", "DNAT", "--to-destination", net.JoinHostPort(destAddr, strconv.Itoa(destPort))} if !c.HairpinMode { args = append(args, "!", "-i", bridgeName) } if err := ProgramRule(Nat, c.Name, action, args); err != nil { return err } args = []string{ "!", "-i", bridgeName, "-o", bridgeName, "-p", proto, "-d", destAddr, "--dport", strconv.Itoa(destPort), "-j", "ACCEPT", } if err := ProgramRule(Filter, c.Name, action, args); err != nil { return err } args = []string{ "-p", proto, "-s", destAddr, "-d", destAddr, "--dport", strconv.Itoa(destPort), "-j", "MASQUERADE", } if err := ProgramRule(Nat, "POSTROUTING", action, args); err != nil { return err } if proto == "sctp" { // Linux kernel v4.9 and below enables NETIF_F_SCTP_CRC for veth by // the following commit. // This introduces a problem when conbined with a physical NIC without // NETIF_F_SCTP_CRC. As for a workaround, here we add an iptables entry // to fill the checksum. // // https://github.com/torvalds/linux/commit/c80fafbbb59ef9924962f83aac85531039395b18 args = []string{ "-p", proto, "--sport", strconv.Itoa(destPort), "-j", "CHECKSUM", "--checksum-fill", } if err := ProgramRule(Mangle, "POSTROUTING", action, args); err != nil { return err } } return nil }
go
func (c *ChainInfo) Forward(action Action, ip net.IP, port int, proto, destAddr string, destPort int, bridgeName string) error { daddr := ip.String() if ip.IsUnspecified() { // iptables interprets "0.0.0.0" as "0.0.0.0/32", whereas we // want "0.0.0.0/0". "0/0" is correctly interpreted as "any // value" by both iptables and ip6tables. daddr = "0/0" } args := []string{ "-p", proto, "-d", daddr, "--dport", strconv.Itoa(port), "-j", "DNAT", "--to-destination", net.JoinHostPort(destAddr, strconv.Itoa(destPort))} if !c.HairpinMode { args = append(args, "!", "-i", bridgeName) } if err := ProgramRule(Nat, c.Name, action, args); err != nil { return err } args = []string{ "!", "-i", bridgeName, "-o", bridgeName, "-p", proto, "-d", destAddr, "--dport", strconv.Itoa(destPort), "-j", "ACCEPT", } if err := ProgramRule(Filter, c.Name, action, args); err != nil { return err } args = []string{ "-p", proto, "-s", destAddr, "-d", destAddr, "--dport", strconv.Itoa(destPort), "-j", "MASQUERADE", } if err := ProgramRule(Nat, "POSTROUTING", action, args); err != nil { return err } if proto == "sctp" { // Linux kernel v4.9 and below enables NETIF_F_SCTP_CRC for veth by // the following commit. // This introduces a problem when conbined with a physical NIC without // NETIF_F_SCTP_CRC. As for a workaround, here we add an iptables entry // to fill the checksum. // // https://github.com/torvalds/linux/commit/c80fafbbb59ef9924962f83aac85531039395b18 args = []string{ "-p", proto, "--sport", strconv.Itoa(destPort), "-j", "CHECKSUM", "--checksum-fill", } if err := ProgramRule(Mangle, "POSTROUTING", action, args); err != nil { return err } } return nil }
[ "func", "(", "c", "*", "ChainInfo", ")", "Forward", "(", "action", "Action", ",", "ip", "net", ".", "IP", ",", "port", "int", ",", "proto", ",", "destAddr", "string", ",", "destPort", "int", ",", "bridgeName", "string", ")", "error", "{", "daddr", ":=", "ip", ".", "String", "(", ")", "\n", "if", "ip", ".", "IsUnspecified", "(", ")", "{", "// iptables interprets \"0.0.0.0\" as \"0.0.0.0/32\", whereas we", "// want \"0.0.0.0/0\". \"0/0\" is correctly interpreted as \"any", "// value\" by both iptables and ip6tables.", "daddr", "=", "\"", "\"", "\n", "}", "\n\n", "args", ":=", "[", "]", "string", "{", "\"", "\"", ",", "proto", ",", "\"", "\"", ",", "daddr", ",", "\"", "\"", ",", "strconv", ".", "Itoa", "(", "port", ")", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "net", ".", "JoinHostPort", "(", "destAddr", ",", "strconv", ".", "Itoa", "(", "destPort", ")", ")", "}", "\n", "if", "!", "c", ".", "HairpinMode", "{", "args", "=", "append", "(", "args", ",", "\"", "\"", ",", "\"", "\"", ",", "bridgeName", ")", "\n", "}", "\n", "if", "err", ":=", "ProgramRule", "(", "Nat", ",", "c", ".", "Name", ",", "action", ",", "args", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "args", "=", "[", "]", "string", "{", "\"", "\"", ",", "\"", "\"", ",", "bridgeName", ",", "\"", "\"", ",", "bridgeName", ",", "\"", "\"", ",", "proto", ",", "\"", "\"", ",", "destAddr", ",", "\"", "\"", ",", "strconv", ".", "Itoa", "(", "destPort", ")", ",", "\"", "\"", ",", "\"", "\"", ",", "}", "\n", "if", "err", ":=", "ProgramRule", "(", "Filter", ",", "c", ".", "Name", ",", "action", ",", "args", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "args", "=", "[", "]", "string", "{", "\"", "\"", ",", "proto", ",", "\"", "\"", ",", "destAddr", ",", "\"", "\"", ",", "destAddr", ",", "\"", "\"", ",", "strconv", ".", "Itoa", "(", "destPort", ")", ",", "\"", "\"", ",", "\"", "\"", ",", "}", "\n\n", "if", "err", ":=", "ProgramRule", "(", "Nat", ",", "\"", "\"", ",", "action", ",", "args", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "proto", "==", "\"", "\"", "{", "// Linux kernel v4.9 and below enables NETIF_F_SCTP_CRC for veth by", "// the following commit.", "// This introduces a problem when conbined with a physical NIC without", "// NETIF_F_SCTP_CRC. As for a workaround, here we add an iptables entry", "// to fill the checksum.", "//", "// https://github.com/torvalds/linux/commit/c80fafbbb59ef9924962f83aac85531039395b18", "args", "=", "[", "]", "string", "{", "\"", "\"", ",", "proto", ",", "\"", "\"", ",", "strconv", ".", "Itoa", "(", "destPort", ")", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "}", "\n", "if", "err", ":=", "ProgramRule", "(", "Mangle", ",", "\"", "\"", ",", "action", ",", "args", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Forward adds forwarding rule to 'filter' table and corresponding nat rule to 'nat' table.
[ "Forward", "adds", "forwarding", "rule", "to", "filter", "table", "and", "corresponding", "nat", "rule", "to", "nat", "table", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/iptables/iptables.go#L239-L305
22,616
docker/libnetwork
iptables/iptables.go
Link
func (c *ChainInfo) Link(action Action, ip1, ip2 net.IP, port int, proto string, bridgeName string) error { // forward args := []string{ "-i", bridgeName, "-o", bridgeName, "-p", proto, "-s", ip1.String(), "-d", ip2.String(), "--dport", strconv.Itoa(port), "-j", "ACCEPT", } if err := ProgramRule(Filter, c.Name, action, args); err != nil { return err } // reverse args[7], args[9] = args[9], args[7] args[10] = "--sport" return ProgramRule(Filter, c.Name, action, args) }
go
func (c *ChainInfo) Link(action Action, ip1, ip2 net.IP, port int, proto string, bridgeName string) error { // forward args := []string{ "-i", bridgeName, "-o", bridgeName, "-p", proto, "-s", ip1.String(), "-d", ip2.String(), "--dport", strconv.Itoa(port), "-j", "ACCEPT", } if err := ProgramRule(Filter, c.Name, action, args); err != nil { return err } // reverse args[7], args[9] = args[9], args[7] args[10] = "--sport" return ProgramRule(Filter, c.Name, action, args) }
[ "func", "(", "c", "*", "ChainInfo", ")", "Link", "(", "action", "Action", ",", "ip1", ",", "ip2", "net", ".", "IP", ",", "port", "int", ",", "proto", "string", ",", "bridgeName", "string", ")", "error", "{", "// forward", "args", ":=", "[", "]", "string", "{", "\"", "\"", ",", "bridgeName", ",", "\"", "\"", ",", "bridgeName", ",", "\"", "\"", ",", "proto", ",", "\"", "\"", ",", "ip1", ".", "String", "(", ")", ",", "\"", "\"", ",", "ip2", ".", "String", "(", ")", ",", "\"", "\"", ",", "strconv", ".", "Itoa", "(", "port", ")", ",", "\"", "\"", ",", "\"", "\"", ",", "}", "\n", "if", "err", ":=", "ProgramRule", "(", "Filter", ",", "c", ".", "Name", ",", "action", ",", "args", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "// reverse", "args", "[", "7", "]", ",", "args", "[", "9", "]", "=", "args", "[", "9", "]", ",", "args", "[", "7", "]", "\n", "args", "[", "10", "]", "=", "\"", "\"", "\n", "return", "ProgramRule", "(", "Filter", ",", "c", ".", "Name", ",", "action", ",", "args", ")", "\n", "}" ]
// Link adds reciprocal ACCEPT rule for two supplied IP addresses. // Traffic is allowed from ip1 to ip2 and vice-versa
[ "Link", "adds", "reciprocal", "ACCEPT", "rule", "for", "two", "supplied", "IP", "addresses", ".", "Traffic", "is", "allowed", "from", "ip1", "to", "ip2", "and", "vice", "-", "versa" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/iptables/iptables.go#L309-L326
22,617
docker/libnetwork
iptables/iptables.go
ProgramRule
func ProgramRule(table Table, chain string, action Action, args []string) error { if Exists(table, chain, args...) != (action == Delete) { return nil } return RawCombinedOutput(append([]string{"-t", string(table), string(action), chain}, args...)...) }
go
func ProgramRule(table Table, chain string, action Action, args []string) error { if Exists(table, chain, args...) != (action == Delete) { return nil } return RawCombinedOutput(append([]string{"-t", string(table), string(action), chain}, args...)...) }
[ "func", "ProgramRule", "(", "table", "Table", ",", "chain", "string", ",", "action", "Action", ",", "args", "[", "]", "string", ")", "error", "{", "if", "Exists", "(", "table", ",", "chain", ",", "args", "...", ")", "!=", "(", "action", "==", "Delete", ")", "{", "return", "nil", "\n", "}", "\n", "return", "RawCombinedOutput", "(", "append", "(", "[", "]", "string", "{", "\"", "\"", ",", "string", "(", "table", ")", ",", "string", "(", "action", ")", ",", "chain", "}", ",", "args", "...", ")", "...", ")", "\n", "}" ]
// ProgramRule adds the rule specified by args only if the // rule is not already present in the chain. Reciprocally, // it removes the rule only if present.
[ "ProgramRule", "adds", "the", "rule", "specified", "by", "args", "only", "if", "the", "rule", "is", "not", "already", "present", "in", "the", "chain", ".", "Reciprocally", "it", "removes", "the", "rule", "only", "if", "present", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/iptables/iptables.go#L331-L336
22,618
docker/libnetwork
iptables/iptables.go
Remove
func (c *ChainInfo) Remove() error { // Ignore errors - This could mean the chains were never set up if c.Table == Nat { c.Prerouting(Delete, "-m", "addrtype", "--dst-type", "LOCAL", "-j", c.Name) c.Output(Delete, "-m", "addrtype", "--dst-type", "LOCAL", "!", "--dst", "127.0.0.0/8", "-j", c.Name) c.Output(Delete, "-m", "addrtype", "--dst-type", "LOCAL", "-j", c.Name) // Created in versions <= 0.1.6 c.Prerouting(Delete) c.Output(Delete) } Raw("-t", string(c.Table), "-F", c.Name) Raw("-t", string(c.Table), "-X", c.Name) return nil }
go
func (c *ChainInfo) Remove() error { // Ignore errors - This could mean the chains were never set up if c.Table == Nat { c.Prerouting(Delete, "-m", "addrtype", "--dst-type", "LOCAL", "-j", c.Name) c.Output(Delete, "-m", "addrtype", "--dst-type", "LOCAL", "!", "--dst", "127.0.0.0/8", "-j", c.Name) c.Output(Delete, "-m", "addrtype", "--dst-type", "LOCAL", "-j", c.Name) // Created in versions <= 0.1.6 c.Prerouting(Delete) c.Output(Delete) } Raw("-t", string(c.Table), "-F", c.Name) Raw("-t", string(c.Table), "-X", c.Name) return nil }
[ "func", "(", "c", "*", "ChainInfo", ")", "Remove", "(", ")", "error", "{", "// Ignore errors - This could mean the chains were never set up", "if", "c", ".", "Table", "==", "Nat", "{", "c", ".", "Prerouting", "(", "Delete", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "c", ".", "Name", ")", "\n", "c", ".", "Output", "(", "Delete", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "c", ".", "Name", ")", "\n", "c", ".", "Output", "(", "Delete", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "c", ".", "Name", ")", "// Created in versions <= 0.1.6", "\n\n", "c", ".", "Prerouting", "(", "Delete", ")", "\n", "c", ".", "Output", "(", "Delete", ")", "\n", "}", "\n", "Raw", "(", "\"", "\"", ",", "string", "(", "c", ".", "Table", ")", ",", "\"", "\"", ",", "c", ".", "Name", ")", "\n", "Raw", "(", "\"", "\"", ",", "string", "(", "c", ".", "Table", ")", ",", "\"", "\"", ",", "c", ".", "Name", ")", "\n", "return", "nil", "\n", "}" ]
// Remove removes the chain.
[ "Remove", "removes", "the", "chain", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/iptables/iptables.go#L367-L380
22,619
docker/libnetwork
iptables/iptables.go
Exists
func Exists(table Table, chain string, rule ...string) bool { return exists(false, table, chain, rule...) }
go
func Exists(table Table, chain string, rule ...string) bool { return exists(false, table, chain, rule...) }
[ "func", "Exists", "(", "table", "Table", ",", "chain", "string", ",", "rule", "...", "string", ")", "bool", "{", "return", "exists", "(", "false", ",", "table", ",", "chain", ",", "rule", "...", ")", "\n", "}" ]
// Exists checks if a rule exists
[ "Exists", "checks", "if", "a", "rule", "exists" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/iptables/iptables.go#L383-L385
22,620
docker/libnetwork
iptables/iptables.go
ExistsNative
func ExistsNative(table Table, chain string, rule ...string) bool { return exists(true, table, chain, rule...) }
go
func ExistsNative(table Table, chain string, rule ...string) bool { return exists(true, table, chain, rule...) }
[ "func", "ExistsNative", "(", "table", "Table", ",", "chain", "string", ",", "rule", "...", "string", ")", "bool", "{", "return", "exists", "(", "true", ",", "table", ",", "chain", ",", "rule", "...", ")", "\n", "}" ]
// ExistsNative behaves as Exists with the difference it // will always invoke `iptables` binary.
[ "ExistsNative", "behaves", "as", "Exists", "with", "the", "difference", "it", "will", "always", "invoke", "iptables", "binary", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/iptables/iptables.go#L389-L391
22,621
docker/libnetwork
iptables/iptables.go
Raw
func Raw(args ...string) ([]byte, error) { if firewalldRunning { startTime := time.Now() output, err := Passthrough(Iptables, args...) if err == nil || !strings.Contains(err.Error(), "was not provided by any .service files") { return filterOutput(startTime, output, args...), err } } return raw(args...) }
go
func Raw(args ...string) ([]byte, error) { if firewalldRunning { startTime := time.Now() output, err := Passthrough(Iptables, args...) if err == nil || !strings.Contains(err.Error(), "was not provided by any .service files") { return filterOutput(startTime, output, args...), err } } return raw(args...) }
[ "func", "Raw", "(", "args", "...", "string", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "if", "firewalldRunning", "{", "startTime", ":=", "time", ".", "Now", "(", ")", "\n", "output", ",", "err", ":=", "Passthrough", "(", "Iptables", ",", "args", "...", ")", "\n", "if", "err", "==", "nil", "||", "!", "strings", ".", "Contains", "(", "err", ".", "Error", "(", ")", ",", "\"", "\"", ")", "{", "return", "filterOutput", "(", "startTime", ",", "output", ",", "args", "...", ")", ",", "err", "\n", "}", "\n", "}", "\n", "return", "raw", "(", "args", "...", ")", "\n", "}" ]
// Raw calls 'iptables' system command, passing supplied arguments.
[ "Raw", "calls", "iptables", "system", "command", "passing", "supplied", "arguments", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/iptables/iptables.go#L447-L456
22,622
docker/libnetwork
iptables/iptables.go
RawCombinedOutput
func RawCombinedOutput(args ...string) error { if output, err := Raw(args...); err != nil || len(output) != 0 { return fmt.Errorf("%s (%v)", string(output), err) } return nil }
go
func RawCombinedOutput(args ...string) error { if output, err := Raw(args...); err != nil || len(output) != 0 { return fmt.Errorf("%s (%v)", string(output), err) } return nil }
[ "func", "RawCombinedOutput", "(", "args", "...", "string", ")", "error", "{", "if", "output", ",", "err", ":=", "Raw", "(", "args", "...", ")", ";", "err", "!=", "nil", "||", "len", "(", "output", ")", "!=", "0", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "string", "(", "output", ")", ",", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// RawCombinedOutput internally calls the Raw function and returns a non nil // error if Raw returned a non nil error or a non empty output
[ "RawCombinedOutput", "internally", "calls", "the", "Raw", "function", "and", "returns", "a", "non", "nil", "error", "if", "Raw", "returned", "a", "non", "nil", "error", "or", "a", "non", "empty", "output" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/iptables/iptables.go#L482-L487
22,623
docker/libnetwork
iptables/iptables.go
RawCombinedOutputNative
func RawCombinedOutputNative(args ...string) error { if output, err := raw(args...); err != nil || len(output) != 0 { return fmt.Errorf("%s (%v)", string(output), err) } return nil }
go
func RawCombinedOutputNative(args ...string) error { if output, err := raw(args...); err != nil || len(output) != 0 { return fmt.Errorf("%s (%v)", string(output), err) } return nil }
[ "func", "RawCombinedOutputNative", "(", "args", "...", "string", ")", "error", "{", "if", "output", ",", "err", ":=", "raw", "(", "args", "...", ")", ";", "err", "!=", "nil", "||", "len", "(", "output", ")", "!=", "0", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "string", "(", "output", ")", ",", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// RawCombinedOutputNative behave as RawCombinedOutput with the difference it // will always invoke `iptables` binary
[ "RawCombinedOutputNative", "behave", "as", "RawCombinedOutput", "with", "the", "difference", "it", "will", "always", "invoke", "iptables", "binary" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/iptables/iptables.go#L491-L496
22,624
docker/libnetwork
iptables/iptables.go
ExistChain
func ExistChain(chain string, table Table) bool { if _, err := Raw("-t", string(table), "-nL", chain); err == nil { return true } return false }
go
func ExistChain(chain string, table Table) bool { if _, err := Raw("-t", string(table), "-nL", chain); err == nil { return true } return false }
[ "func", "ExistChain", "(", "chain", "string", ",", "table", "Table", ")", "bool", "{", "if", "_", ",", "err", ":=", "Raw", "(", "\"", "\"", ",", "string", "(", "table", ")", ",", "\"", "\"", ",", "chain", ")", ";", "err", "==", "nil", "{", "return", "true", "\n", "}", "\n", "return", "false", "\n", "}" ]
// ExistChain checks if a chain exists
[ "ExistChain", "checks", "if", "a", "chain", "exists" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/iptables/iptables.go#L499-L504
22,625
docker/libnetwork
iptables/iptables.go
GetVersion
func GetVersion() (major, minor, micro int, err error) { out, err := exec.Command(iptablesPath, "--version").CombinedOutput() if err == nil { major, minor, micro = parseVersionNumbers(string(out)) } return }
go
func GetVersion() (major, minor, micro int, err error) { out, err := exec.Command(iptablesPath, "--version").CombinedOutput() if err == nil { major, minor, micro = parseVersionNumbers(string(out)) } return }
[ "func", "GetVersion", "(", ")", "(", "major", ",", "minor", ",", "micro", "int", ",", "err", "error", ")", "{", "out", ",", "err", ":=", "exec", ".", "Command", "(", "iptablesPath", ",", "\"", "\"", ")", ".", "CombinedOutput", "(", ")", "\n", "if", "err", "==", "nil", "{", "major", ",", "minor", ",", "micro", "=", "parseVersionNumbers", "(", "string", "(", "out", ")", ")", "\n", "}", "\n", "return", "\n", "}" ]
// GetVersion reads the iptables version numbers during initialization
[ "GetVersion", "reads", "the", "iptables", "version", "numbers", "during", "initialization" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/iptables/iptables.go#L507-L513
22,626
docker/libnetwork
iptables/iptables.go
AddReturnRule
func AddReturnRule(chain string) error { var ( table = Filter args = []string{"-j", "RETURN"} ) if Exists(table, chain, args...) { return nil } err := RawCombinedOutput(append([]string{"-A", chain}, args...)...) if err != nil { return fmt.Errorf("unable to add return rule in %s chain: %s", chain, err.Error()) } return nil }
go
func AddReturnRule(chain string) error { var ( table = Filter args = []string{"-j", "RETURN"} ) if Exists(table, chain, args...) { return nil } err := RawCombinedOutput(append([]string{"-A", chain}, args...)...) if err != nil { return fmt.Errorf("unable to add return rule in %s chain: %s", chain, err.Error()) } return nil }
[ "func", "AddReturnRule", "(", "chain", "string", ")", "error", "{", "var", "(", "table", "=", "Filter", "\n", "args", "=", "[", "]", "string", "{", "\"", "\"", ",", "\"", "\"", "}", "\n", ")", "\n\n", "if", "Exists", "(", "table", ",", "chain", ",", "args", "...", ")", "{", "return", "nil", "\n", "}", "\n\n", "err", ":=", "RawCombinedOutput", "(", "append", "(", "[", "]", "string", "{", "\"", "\"", ",", "chain", "}", ",", "args", "...", ")", "...", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "chain", ",", "err", ".", "Error", "(", ")", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// AddReturnRule adds a return rule for the chain in the filter table
[ "AddReturnRule", "adds", "a", "return", "rule", "for", "the", "chain", "in", "the", "filter", "table" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/iptables/iptables.go#L537-L553
22,627
docker/libnetwork
iptables/iptables.go
EnsureJumpRule
func EnsureJumpRule(fromChain, toChain string) error { var ( table = Filter args = []string{"-j", toChain} ) if Exists(table, fromChain, args...) { err := RawCombinedOutput(append([]string{"-D", fromChain}, args...)...) if err != nil { return fmt.Errorf("unable to remove jump to %s rule in %s chain: %s", toChain, fromChain, err.Error()) } } err := RawCombinedOutput(append([]string{"-I", fromChain}, args...)...) if err != nil { return fmt.Errorf("unable to insert jump to %s rule in %s chain: %s", toChain, fromChain, err.Error()) } return nil }
go
func EnsureJumpRule(fromChain, toChain string) error { var ( table = Filter args = []string{"-j", toChain} ) if Exists(table, fromChain, args...) { err := RawCombinedOutput(append([]string{"-D", fromChain}, args...)...) if err != nil { return fmt.Errorf("unable to remove jump to %s rule in %s chain: %s", toChain, fromChain, err.Error()) } } err := RawCombinedOutput(append([]string{"-I", fromChain}, args...)...) if err != nil { return fmt.Errorf("unable to insert jump to %s rule in %s chain: %s", toChain, fromChain, err.Error()) } return nil }
[ "func", "EnsureJumpRule", "(", "fromChain", ",", "toChain", "string", ")", "error", "{", "var", "(", "table", "=", "Filter", "\n", "args", "=", "[", "]", "string", "{", "\"", "\"", ",", "toChain", "}", "\n", ")", "\n\n", "if", "Exists", "(", "table", ",", "fromChain", ",", "args", "...", ")", "{", "err", ":=", "RawCombinedOutput", "(", "append", "(", "[", "]", "string", "{", "\"", "\"", ",", "fromChain", "}", ",", "args", "...", ")", "...", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "toChain", ",", "fromChain", ",", "err", ".", "Error", "(", ")", ")", "\n", "}", "\n", "}", "\n\n", "err", ":=", "RawCombinedOutput", "(", "append", "(", "[", "]", "string", "{", "\"", "\"", ",", "fromChain", "}", ",", "args", "...", ")", "...", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "toChain", ",", "fromChain", ",", "err", ".", "Error", "(", ")", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// EnsureJumpRule ensures the jump rule is on top
[ "EnsureJumpRule", "ensures", "the", "jump", "rule", "is", "on", "top" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/iptables/iptables.go#L556-L575
22,628
docker/libnetwork
client/network.go
CmdNetwork
func (cli *NetworkCli) CmdNetwork(chain string, args ...string) error { cmd := cli.Subcmd(chain, "network", "COMMAND [OPTIONS] [arg...]", networkUsage(chain), false) cmd.Require(flag.Min, 1) err := cmd.ParseFlags(args, true) if err == nil { cmd.Usage() return fmt.Errorf("invalid command : %v", args) } return err }
go
func (cli *NetworkCli) CmdNetwork(chain string, args ...string) error { cmd := cli.Subcmd(chain, "network", "COMMAND [OPTIONS] [arg...]", networkUsage(chain), false) cmd.Require(flag.Min, 1) err := cmd.ParseFlags(args, true) if err == nil { cmd.Usage() return fmt.Errorf("invalid command : %v", args) } return err }
[ "func", "(", "cli", "*", "NetworkCli", ")", "CmdNetwork", "(", "chain", "string", ",", "args", "...", "string", ")", "error", "{", "cmd", ":=", "cli", ".", "Subcmd", "(", "chain", ",", "\"", "\"", ",", "\"", "\"", ",", "networkUsage", "(", "chain", ")", ",", "false", ")", "\n", "cmd", ".", "Require", "(", "flag", ".", "Min", ",", "1", ")", "\n", "err", ":=", "cmd", ".", "ParseFlags", "(", "args", ",", "true", ")", "\n", "if", "err", "==", "nil", "{", "cmd", ".", "Usage", "(", ")", "\n", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "args", ")", "\n", "}", "\n", "return", "err", "\n", "}" ]
// CmdNetwork handles the root Network UI
[ "CmdNetwork", "handles", "the", "root", "Network", "UI" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/network.go#L31-L40
22,629
docker/libnetwork
client/network.go
CmdNetworkCreate
func (cli *NetworkCli) CmdNetworkCreate(chain string, args ...string) error { cmd := cli.Subcmd(chain, "create", "NETWORK-NAME", "Creates a new network with a name specified by the user", false) flDriver := cmd.String([]string{"d", "-driver"}, "", "Driver to manage the Network") flID := cmd.String([]string{"-id"}, "", "Network ID string") flOpts := cmd.String([]string{"o", "-opt"}, "", "Network options") flInternal := cmd.Bool([]string{"-internal"}, false, "Config the network to be internal") flIPv6 := cmd.Bool([]string{"-ipv6"}, false, "Enable IPv6 on the network") flSubnet := cmd.String([]string{"-subnet"}, "", "Subnet option") flRange := cmd.String([]string{"-ip-range"}, "", "Range option") cmd.Require(flag.Exact, 1) err := cmd.ParseFlags(args, true) if err != nil { return err } networkOpts := make(map[string]string) if *flInternal { networkOpts[netlabel.Internal] = "true" } if *flIPv6 { networkOpts[netlabel.EnableIPv6] = "true" } driverOpts := make(map[string]string) if *flOpts != "" { opts := strings.Split(*flOpts, ",") for _, opt := range opts { driverOpts[netlabel.Key(opt)] = netlabel.Value(opt) } } var icList []ipamConf if *flSubnet != "" { ic := ipamConf{ PreferredPool: *flSubnet, } if *flRange != "" { ic.SubPool = *flRange } icList = append(icList, ic) } // Construct network create request body nc := networkCreate{Name: cmd.Arg(0), NetworkType: *flDriver, ID: *flID, IPv4Conf: icList, DriverOpts: driverOpts, NetworkOpts: networkOpts} obj, _, err := readBody(cli.call("POST", "/networks", nc, nil)) if err != nil { return err } var replyID string err = json.Unmarshal(obj, &replyID) if err != nil { return err } fmt.Fprintf(cli.out, "%s\n", replyID) return nil }
go
func (cli *NetworkCli) CmdNetworkCreate(chain string, args ...string) error { cmd := cli.Subcmd(chain, "create", "NETWORK-NAME", "Creates a new network with a name specified by the user", false) flDriver := cmd.String([]string{"d", "-driver"}, "", "Driver to manage the Network") flID := cmd.String([]string{"-id"}, "", "Network ID string") flOpts := cmd.String([]string{"o", "-opt"}, "", "Network options") flInternal := cmd.Bool([]string{"-internal"}, false, "Config the network to be internal") flIPv6 := cmd.Bool([]string{"-ipv6"}, false, "Enable IPv6 on the network") flSubnet := cmd.String([]string{"-subnet"}, "", "Subnet option") flRange := cmd.String([]string{"-ip-range"}, "", "Range option") cmd.Require(flag.Exact, 1) err := cmd.ParseFlags(args, true) if err != nil { return err } networkOpts := make(map[string]string) if *flInternal { networkOpts[netlabel.Internal] = "true" } if *flIPv6 { networkOpts[netlabel.EnableIPv6] = "true" } driverOpts := make(map[string]string) if *flOpts != "" { opts := strings.Split(*flOpts, ",") for _, opt := range opts { driverOpts[netlabel.Key(opt)] = netlabel.Value(opt) } } var icList []ipamConf if *flSubnet != "" { ic := ipamConf{ PreferredPool: *flSubnet, } if *flRange != "" { ic.SubPool = *flRange } icList = append(icList, ic) } // Construct network create request body nc := networkCreate{Name: cmd.Arg(0), NetworkType: *flDriver, ID: *flID, IPv4Conf: icList, DriverOpts: driverOpts, NetworkOpts: networkOpts} obj, _, err := readBody(cli.call("POST", "/networks", nc, nil)) if err != nil { return err } var replyID string err = json.Unmarshal(obj, &replyID) if err != nil { return err } fmt.Fprintf(cli.out, "%s\n", replyID) return nil }
[ "func", "(", "cli", "*", "NetworkCli", ")", "CmdNetworkCreate", "(", "chain", "string", ",", "args", "...", "string", ")", "error", "{", "cmd", ":=", "cli", ".", "Subcmd", "(", "chain", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "false", ")", "\n", "flDriver", ":=", "cmd", ".", "String", "(", "[", "]", "string", "{", "\"", "\"", ",", "\"", "\"", "}", ",", "\"", "\"", ",", "\"", "\"", ")", "\n", "flID", ":=", "cmd", ".", "String", "(", "[", "]", "string", "{", "\"", "\"", "}", ",", "\"", "\"", ",", "\"", "\"", ")", "\n", "flOpts", ":=", "cmd", ".", "String", "(", "[", "]", "string", "{", "\"", "\"", ",", "\"", "\"", "}", ",", "\"", "\"", ",", "\"", "\"", ")", "\n", "flInternal", ":=", "cmd", ".", "Bool", "(", "[", "]", "string", "{", "\"", "\"", "}", ",", "false", ",", "\"", "\"", ")", "\n", "flIPv6", ":=", "cmd", ".", "Bool", "(", "[", "]", "string", "{", "\"", "\"", "}", ",", "false", ",", "\"", "\"", ")", "\n", "flSubnet", ":=", "cmd", ".", "String", "(", "[", "]", "string", "{", "\"", "\"", "}", ",", "\"", "\"", ",", "\"", "\"", ")", "\n", "flRange", ":=", "cmd", ".", "String", "(", "[", "]", "string", "{", "\"", "\"", "}", ",", "\"", "\"", ",", "\"", "\"", ")", "\n\n", "cmd", ".", "Require", "(", "flag", ".", "Exact", ",", "1", ")", "\n", "err", ":=", "cmd", ".", "ParseFlags", "(", "args", ",", "true", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "networkOpts", ":=", "make", "(", "map", "[", "string", "]", "string", ")", "\n", "if", "*", "flInternal", "{", "networkOpts", "[", "netlabel", ".", "Internal", "]", "=", "\"", "\"", "\n", "}", "\n", "if", "*", "flIPv6", "{", "networkOpts", "[", "netlabel", ".", "EnableIPv6", "]", "=", "\"", "\"", "\n", "}", "\n\n", "driverOpts", ":=", "make", "(", "map", "[", "string", "]", "string", ")", "\n", "if", "*", "flOpts", "!=", "\"", "\"", "{", "opts", ":=", "strings", ".", "Split", "(", "*", "flOpts", ",", "\"", "\"", ")", "\n", "for", "_", ",", "opt", ":=", "range", "opts", "{", "driverOpts", "[", "netlabel", ".", "Key", "(", "opt", ")", "]", "=", "netlabel", ".", "Value", "(", "opt", ")", "\n", "}", "\n", "}", "\n\n", "var", "icList", "[", "]", "ipamConf", "\n", "if", "*", "flSubnet", "!=", "\"", "\"", "{", "ic", ":=", "ipamConf", "{", "PreferredPool", ":", "*", "flSubnet", ",", "}", "\n\n", "if", "*", "flRange", "!=", "\"", "\"", "{", "ic", ".", "SubPool", "=", "*", "flRange", "\n", "}", "\n\n", "icList", "=", "append", "(", "icList", ",", "ic", ")", "\n", "}", "\n\n", "// Construct network create request body", "nc", ":=", "networkCreate", "{", "Name", ":", "cmd", ".", "Arg", "(", "0", ")", ",", "NetworkType", ":", "*", "flDriver", ",", "ID", ":", "*", "flID", ",", "IPv4Conf", ":", "icList", ",", "DriverOpts", ":", "driverOpts", ",", "NetworkOpts", ":", "networkOpts", "}", "\n", "obj", ",", "_", ",", "err", ":=", "readBody", "(", "cli", ".", "call", "(", "\"", "\"", ",", "\"", "\"", ",", "nc", ",", "nil", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "var", "replyID", "string", "\n", "err", "=", "json", ".", "Unmarshal", "(", "obj", ",", "&", "replyID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "fmt", ".", "Fprintf", "(", "cli", ".", "out", ",", "\"", "\\n", "\"", ",", "replyID", ")", "\n", "return", "nil", "\n", "}" ]
// CmdNetworkCreate handles Network Create UI
[ "CmdNetworkCreate", "handles", "Network", "Create", "UI" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/network.go#L43-L100
22,630
docker/libnetwork
client/network.go
CmdNetworkRm
func (cli *NetworkCli) CmdNetworkRm(chain string, args ...string) error { cmd := cli.Subcmd(chain, "rm", "NETWORK", "Deletes a network", false) cmd.Require(flag.Exact, 1) err := cmd.ParseFlags(args, true) if err != nil { return err } id, err := lookupNetworkID(cli, cmd.Arg(0)) if err != nil { return err } _, _, err = readBody(cli.call("DELETE", "/networks/"+id, nil, nil)) if err != nil { return err } return nil }
go
func (cli *NetworkCli) CmdNetworkRm(chain string, args ...string) error { cmd := cli.Subcmd(chain, "rm", "NETWORK", "Deletes a network", false) cmd.Require(flag.Exact, 1) err := cmd.ParseFlags(args, true) if err != nil { return err } id, err := lookupNetworkID(cli, cmd.Arg(0)) if err != nil { return err } _, _, err = readBody(cli.call("DELETE", "/networks/"+id, nil, nil)) if err != nil { return err } return nil }
[ "func", "(", "cli", "*", "NetworkCli", ")", "CmdNetworkRm", "(", "chain", "string", ",", "args", "...", "string", ")", "error", "{", "cmd", ":=", "cli", ".", "Subcmd", "(", "chain", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "false", ")", "\n", "cmd", ".", "Require", "(", "flag", ".", "Exact", ",", "1", ")", "\n", "err", ":=", "cmd", ".", "ParseFlags", "(", "args", ",", "true", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "id", ",", "err", ":=", "lookupNetworkID", "(", "cli", ",", "cmd", ".", "Arg", "(", "0", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "_", ",", "_", ",", "err", "=", "readBody", "(", "cli", ".", "call", "(", "\"", "\"", ",", "\"", "\"", "+", "id", ",", "nil", ",", "nil", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// CmdNetworkRm handles Network Delete UI
[ "CmdNetworkRm", "handles", "Network", "Delete", "UI" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/network.go#L103-L119
22,631
docker/libnetwork
client/network.go
CmdNetworkLs
func (cli *NetworkCli) CmdNetworkLs(chain string, args ...string) error { cmd := cli.Subcmd(chain, "ls", "", "Lists all the networks created by the user", false) quiet := cmd.Bool([]string{"q", "-quiet"}, false, "Only display numeric IDs") noTrunc := cmd.Bool([]string{"#notrunc", "-no-trunc"}, false, "Do not truncate the output") nLatest := cmd.Bool([]string{"l", "-latest"}, false, "Show the latest network created") last := cmd.Int([]string{"n"}, -1, "Show n last created networks") err := cmd.ParseFlags(args, true) if err != nil { return err } obj, _, err := readBody(cli.call("GET", "/networks", nil, nil)) if err != nil { return err } if *last == -1 && *nLatest { *last = 1 } var networkResources []networkResource err = json.Unmarshal(obj, &networkResources) if err != nil { return err } wr := tabwriter.NewWriter(cli.out, 20, 1, 3, ' ', 0) // unless quiet (-q) is specified, print field titles if !*quiet { fmt.Fprintln(wr, "NETWORK ID\tNAME\tTYPE") } for _, networkResource := range networkResources { ID := networkResource.ID netName := networkResource.Name if !*noTrunc { ID = stringid.TruncateID(ID) } if *quiet { fmt.Fprintln(wr, ID) continue } netType := networkResource.Type fmt.Fprintf(wr, "%s\t%s\t%s\t", ID, netName, netType) fmt.Fprint(wr, "\n") } wr.Flush() return nil }
go
func (cli *NetworkCli) CmdNetworkLs(chain string, args ...string) error { cmd := cli.Subcmd(chain, "ls", "", "Lists all the networks created by the user", false) quiet := cmd.Bool([]string{"q", "-quiet"}, false, "Only display numeric IDs") noTrunc := cmd.Bool([]string{"#notrunc", "-no-trunc"}, false, "Do not truncate the output") nLatest := cmd.Bool([]string{"l", "-latest"}, false, "Show the latest network created") last := cmd.Int([]string{"n"}, -1, "Show n last created networks") err := cmd.ParseFlags(args, true) if err != nil { return err } obj, _, err := readBody(cli.call("GET", "/networks", nil, nil)) if err != nil { return err } if *last == -1 && *nLatest { *last = 1 } var networkResources []networkResource err = json.Unmarshal(obj, &networkResources) if err != nil { return err } wr := tabwriter.NewWriter(cli.out, 20, 1, 3, ' ', 0) // unless quiet (-q) is specified, print field titles if !*quiet { fmt.Fprintln(wr, "NETWORK ID\tNAME\tTYPE") } for _, networkResource := range networkResources { ID := networkResource.ID netName := networkResource.Name if !*noTrunc { ID = stringid.TruncateID(ID) } if *quiet { fmt.Fprintln(wr, ID) continue } netType := networkResource.Type fmt.Fprintf(wr, "%s\t%s\t%s\t", ID, netName, netType) fmt.Fprint(wr, "\n") } wr.Flush() return nil }
[ "func", "(", "cli", "*", "NetworkCli", ")", "CmdNetworkLs", "(", "chain", "string", ",", "args", "...", "string", ")", "error", "{", "cmd", ":=", "cli", ".", "Subcmd", "(", "chain", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "false", ")", "\n", "quiet", ":=", "cmd", ".", "Bool", "(", "[", "]", "string", "{", "\"", "\"", ",", "\"", "\"", "}", ",", "false", ",", "\"", "\"", ")", "\n", "noTrunc", ":=", "cmd", ".", "Bool", "(", "[", "]", "string", "{", "\"", "\"", ",", "\"", "\"", "}", ",", "false", ",", "\"", "\"", ")", "\n", "nLatest", ":=", "cmd", ".", "Bool", "(", "[", "]", "string", "{", "\"", "\"", ",", "\"", "\"", "}", ",", "false", ",", "\"", "\"", ")", "\n", "last", ":=", "cmd", ".", "Int", "(", "[", "]", "string", "{", "\"", "\"", "}", ",", "-", "1", ",", "\"", "\"", ")", "\n", "err", ":=", "cmd", ".", "ParseFlags", "(", "args", ",", "true", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "obj", ",", "_", ",", "err", ":=", "readBody", "(", "cli", ".", "call", "(", "\"", "\"", ",", "\"", "\"", ",", "nil", ",", "nil", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "*", "last", "==", "-", "1", "&&", "*", "nLatest", "{", "*", "last", "=", "1", "\n", "}", "\n\n", "var", "networkResources", "[", "]", "networkResource", "\n", "err", "=", "json", ".", "Unmarshal", "(", "obj", ",", "&", "networkResources", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "wr", ":=", "tabwriter", ".", "NewWriter", "(", "cli", ".", "out", ",", "20", ",", "1", ",", "3", ",", "' '", ",", "0", ")", "\n\n", "// unless quiet (-q) is specified, print field titles", "if", "!", "*", "quiet", "{", "fmt", ".", "Fprintln", "(", "wr", ",", "\"", "\\t", "\\t", "\"", ")", "\n", "}", "\n\n", "for", "_", ",", "networkResource", ":=", "range", "networkResources", "{", "ID", ":=", "networkResource", ".", "ID", "\n", "netName", ":=", "networkResource", ".", "Name", "\n", "if", "!", "*", "noTrunc", "{", "ID", "=", "stringid", ".", "TruncateID", "(", "ID", ")", "\n", "}", "\n", "if", "*", "quiet", "{", "fmt", ".", "Fprintln", "(", "wr", ",", "ID", ")", "\n", "continue", "\n", "}", "\n", "netType", ":=", "networkResource", ".", "Type", "\n", "fmt", ".", "Fprintf", "(", "wr", ",", "\"", "\\t", "\\t", "\\t", "\"", ",", "ID", ",", "netName", ",", "netType", ")", "\n", "fmt", ".", "Fprint", "(", "wr", ",", "\"", "\\n", "\"", ")", "\n", "}", "\n", "wr", ".", "Flush", "(", ")", "\n", "return", "nil", "\n", "}" ]
// CmdNetworkLs handles Network List UI
[ "CmdNetworkLs", "handles", "Network", "List", "UI" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/network.go#L122-L172
22,632
docker/libnetwork
client/network.go
CmdNetworkInfo
func (cli *NetworkCli) CmdNetworkInfo(chain string, args ...string) error { cmd := cli.Subcmd(chain, "info", "NETWORK", "Displays detailed information on a network", false) cmd.Require(flag.Exact, 1) err := cmd.ParseFlags(args, true) if err != nil { return err } id, err := lookupNetworkID(cli, cmd.Arg(0)) if err != nil { return err } obj, _, err := readBody(cli.call("GET", "/networks/"+id, nil, nil)) if err != nil { return err } networkResource := &networkResource{} if err := json.NewDecoder(bytes.NewReader(obj)).Decode(networkResource); err != nil { return err } fmt.Fprintf(cli.out, "Network Id: %s\n", networkResource.ID) fmt.Fprintf(cli.out, "Name: %s\n", networkResource.Name) fmt.Fprintf(cli.out, "Type: %s\n", networkResource.Type) if networkResource.Services != nil { for _, serviceResource := range networkResource.Services { fmt.Fprintf(cli.out, " Service Id: %s\n", serviceResource.ID) fmt.Fprintf(cli.out, "\tName: %s\n", serviceResource.Name) } } return nil }
go
func (cli *NetworkCli) CmdNetworkInfo(chain string, args ...string) error { cmd := cli.Subcmd(chain, "info", "NETWORK", "Displays detailed information on a network", false) cmd.Require(flag.Exact, 1) err := cmd.ParseFlags(args, true) if err != nil { return err } id, err := lookupNetworkID(cli, cmd.Arg(0)) if err != nil { return err } obj, _, err := readBody(cli.call("GET", "/networks/"+id, nil, nil)) if err != nil { return err } networkResource := &networkResource{} if err := json.NewDecoder(bytes.NewReader(obj)).Decode(networkResource); err != nil { return err } fmt.Fprintf(cli.out, "Network Id: %s\n", networkResource.ID) fmt.Fprintf(cli.out, "Name: %s\n", networkResource.Name) fmt.Fprintf(cli.out, "Type: %s\n", networkResource.Type) if networkResource.Services != nil { for _, serviceResource := range networkResource.Services { fmt.Fprintf(cli.out, " Service Id: %s\n", serviceResource.ID) fmt.Fprintf(cli.out, "\tName: %s\n", serviceResource.Name) } } return nil }
[ "func", "(", "cli", "*", "NetworkCli", ")", "CmdNetworkInfo", "(", "chain", "string", ",", "args", "...", "string", ")", "error", "{", "cmd", ":=", "cli", ".", "Subcmd", "(", "chain", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "false", ")", "\n", "cmd", ".", "Require", "(", "flag", ".", "Exact", ",", "1", ")", "\n", "err", ":=", "cmd", ".", "ParseFlags", "(", "args", ",", "true", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "id", ",", "err", ":=", "lookupNetworkID", "(", "cli", ",", "cmd", ".", "Arg", "(", "0", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "obj", ",", "_", ",", "err", ":=", "readBody", "(", "cli", ".", "call", "(", "\"", "\"", ",", "\"", "\"", "+", "id", ",", "nil", ",", "nil", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "networkResource", ":=", "&", "networkResource", "{", "}", "\n", "if", "err", ":=", "json", ".", "NewDecoder", "(", "bytes", ".", "NewReader", "(", "obj", ")", ")", ".", "Decode", "(", "networkResource", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "fmt", ".", "Fprintf", "(", "cli", ".", "out", ",", "\"", "\\n", "\"", ",", "networkResource", ".", "ID", ")", "\n", "fmt", ".", "Fprintf", "(", "cli", ".", "out", ",", "\"", "\\n", "\"", ",", "networkResource", ".", "Name", ")", "\n", "fmt", ".", "Fprintf", "(", "cli", ".", "out", ",", "\"", "\\n", "\"", ",", "networkResource", ".", "Type", ")", "\n", "if", "networkResource", ".", "Services", "!=", "nil", "{", "for", "_", ",", "serviceResource", ":=", "range", "networkResource", ".", "Services", "{", "fmt", ".", "Fprintf", "(", "cli", ".", "out", ",", "\"", "\\n", "\"", ",", "serviceResource", ".", "ID", ")", "\n", "fmt", ".", "Fprintf", "(", "cli", ".", "out", ",", "\"", "\\t", "\\n", "\"", ",", "serviceResource", ".", "Name", ")", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// CmdNetworkInfo handles Network Info UI
[ "CmdNetworkInfo", "handles", "Network", "Info", "UI" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/network.go#L175-L207
22,633
docker/libnetwork
client/network.go
lookupNetworkID
func lookupNetworkID(cli *NetworkCli, nameID string) (string, error) { obj, statusCode, err := readBody(cli.call("GET", "/networks?name="+nameID, nil, nil)) if err != nil { return "", err } if statusCode != http.StatusOK { return "", fmt.Errorf("name query failed for %s due to : statuscode(%d) %v", nameID, statusCode, string(obj)) } var list []*networkResource err = json.Unmarshal(obj, &list) if err != nil { return "", err } if len(list) > 0 { // name query filter will always return a single-element collection return list[0].ID, nil } // Check for Partial-id obj, statusCode, err = readBody(cli.call("GET", "/networks?partial-id="+nameID, nil, nil)) if err != nil { return "", err } if statusCode != http.StatusOK { return "", fmt.Errorf("partial-id match query failed for %s due to : statuscode(%d) %v", nameID, statusCode, string(obj)) } err = json.Unmarshal(obj, &list) if err != nil { return "", err } if len(list) == 0 { return "", fmt.Errorf("resource not found %s", nameID) } if len(list) > 1 { return "", fmt.Errorf("multiple Networks matching the partial identifier (%s). Please use full identifier", nameID) } return list[0].ID, nil }
go
func lookupNetworkID(cli *NetworkCli, nameID string) (string, error) { obj, statusCode, err := readBody(cli.call("GET", "/networks?name="+nameID, nil, nil)) if err != nil { return "", err } if statusCode != http.StatusOK { return "", fmt.Errorf("name query failed for %s due to : statuscode(%d) %v", nameID, statusCode, string(obj)) } var list []*networkResource err = json.Unmarshal(obj, &list) if err != nil { return "", err } if len(list) > 0 { // name query filter will always return a single-element collection return list[0].ID, nil } // Check for Partial-id obj, statusCode, err = readBody(cli.call("GET", "/networks?partial-id="+nameID, nil, nil)) if err != nil { return "", err } if statusCode != http.StatusOK { return "", fmt.Errorf("partial-id match query failed for %s due to : statuscode(%d) %v", nameID, statusCode, string(obj)) } err = json.Unmarshal(obj, &list) if err != nil { return "", err } if len(list) == 0 { return "", fmt.Errorf("resource not found %s", nameID) } if len(list) > 1 { return "", fmt.Errorf("multiple Networks matching the partial identifier (%s). Please use full identifier", nameID) } return list[0].ID, nil }
[ "func", "lookupNetworkID", "(", "cli", "*", "NetworkCli", ",", "nameID", "string", ")", "(", "string", ",", "error", ")", "{", "obj", ",", "statusCode", ",", "err", ":=", "readBody", "(", "cli", ".", "call", "(", "\"", "\"", ",", "\"", "\"", "+", "nameID", ",", "nil", ",", "nil", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n\n", "if", "statusCode", "!=", "http", ".", "StatusOK", "{", "return", "\"", "\"", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "nameID", ",", "statusCode", ",", "string", "(", "obj", ")", ")", "\n", "}", "\n\n", "var", "list", "[", "]", "*", "networkResource", "\n", "err", "=", "json", ".", "Unmarshal", "(", "obj", ",", "&", "list", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n", "if", "len", "(", "list", ")", ">", "0", "{", "// name query filter will always return a single-element collection", "return", "list", "[", "0", "]", ".", "ID", ",", "nil", "\n", "}", "\n\n", "// Check for Partial-id", "obj", ",", "statusCode", ",", "err", "=", "readBody", "(", "cli", ".", "call", "(", "\"", "\"", ",", "\"", "\"", "+", "nameID", ",", "nil", ",", "nil", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n\n", "if", "statusCode", "!=", "http", ".", "StatusOK", "{", "return", "\"", "\"", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "nameID", ",", "statusCode", ",", "string", "(", "obj", ")", ")", "\n", "}", "\n\n", "err", "=", "json", ".", "Unmarshal", "(", "obj", ",", "&", "list", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n", "if", "len", "(", "list", ")", "==", "0", "{", "return", "\"", "\"", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "nameID", ")", "\n", "}", "\n", "if", "len", "(", "list", ")", ">", "1", "{", "return", "\"", "\"", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "nameID", ")", "\n", "}", "\n", "return", "list", "[", "0", "]", ".", "ID", ",", "nil", "\n", "}" ]
// Helper function to predict if a string is a name or id or partial-id // This provides a best-effort mechanism to identify an id with the help of GET Filter APIs // Being a UI, its most likely that name will be used by the user, which is used to lookup // the corresponding ID. If ID is not found, this function will assume that the passed string // is an ID by itself.
[ "Helper", "function", "to", "predict", "if", "a", "string", "is", "a", "name", "or", "id", "or", "partial", "-", "id", "This", "provides", "a", "best", "-", "effort", "mechanism", "to", "identify", "an", "id", "with", "the", "help", "of", "GET", "Filter", "APIs", "Being", "a", "UI", "its", "most", "likely", "that", "name", "will", "be", "used", "by", "the", "user", "which", "is", "used", "to", "lookup", "the", "corresponding", "ID", ".", "If", "ID", "is", "not", "found", "this", "function", "will", "assume", "that", "the", "passed", "string", "is", "an", "ID", "by", "itself", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/network.go#L215-L256
22,634
docker/libnetwork
drivers/ipvlan/ipvlan.go
Init
func Init(dc driverapi.DriverCallback, config map[string]interface{}) error { c := driverapi.Capability{ DataScope: datastore.LocalScope, ConnectivityScope: datastore.GlobalScope, } d := &driver{ networks: networkTable{}, } d.initStore(config) return dc.RegisterDriver(ipvlanType, d, c) }
go
func Init(dc driverapi.DriverCallback, config map[string]interface{}) error { c := driverapi.Capability{ DataScope: datastore.LocalScope, ConnectivityScope: datastore.GlobalScope, } d := &driver{ networks: networkTable{}, } d.initStore(config) return dc.RegisterDriver(ipvlanType, d, c) }
[ "func", "Init", "(", "dc", "driverapi", ".", "DriverCallback", ",", "config", "map", "[", "string", "]", "interface", "{", "}", ")", "error", "{", "c", ":=", "driverapi", ".", "Capability", "{", "DataScope", ":", "datastore", ".", "LocalScope", ",", "ConnectivityScope", ":", "datastore", ".", "GlobalScope", ",", "}", "\n", "d", ":=", "&", "driver", "{", "networks", ":", "networkTable", "{", "}", ",", "}", "\n", "d", ".", "initStore", "(", "config", ")", "\n\n", "return", "dc", ".", "RegisterDriver", "(", "ipvlanType", ",", "d", ",", "c", ")", "\n", "}" ]
// Init initializes and registers the libnetwork ipvlan driver
[ "Init", "initializes", "and", "registers", "the", "libnetwork", "ipvlan", "driver" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/ipvlan/ipvlan.go#L59-L70
22,635
docker/libnetwork
networkdb/networkdb.go
DefaultConfig
func DefaultConfig() *Config { hostname, _ := os.Hostname() return &Config{ NodeID: stringid.TruncateID(stringid.GenerateRandomID()), Hostname: hostname, BindAddr: "0.0.0.0", PacketBufferSize: 1400, StatsPrintPeriod: 5 * time.Minute, HealthPrintPeriod: 1 * time.Minute, reapEntryInterval: 30 * time.Minute, } }
go
func DefaultConfig() *Config { hostname, _ := os.Hostname() return &Config{ NodeID: stringid.TruncateID(stringid.GenerateRandomID()), Hostname: hostname, BindAddr: "0.0.0.0", PacketBufferSize: 1400, StatsPrintPeriod: 5 * time.Minute, HealthPrintPeriod: 1 * time.Minute, reapEntryInterval: 30 * time.Minute, } }
[ "func", "DefaultConfig", "(", ")", "*", "Config", "{", "hostname", ",", "_", ":=", "os", ".", "Hostname", "(", ")", "\n", "return", "&", "Config", "{", "NodeID", ":", "stringid", ".", "TruncateID", "(", "stringid", ".", "GenerateRandomID", "(", ")", ")", ",", "Hostname", ":", "hostname", ",", "BindAddr", ":", "\"", "\"", ",", "PacketBufferSize", ":", "1400", ",", "StatsPrintPeriod", ":", "5", "*", "time", ".", "Minute", ",", "HealthPrintPeriod", ":", "1", "*", "time", ".", "Minute", ",", "reapEntryInterval", ":", "30", "*", "time", ".", "Minute", ",", "}", "\n", "}" ]
// DefaultConfig returns a NetworkDB config with default values
[ "DefaultConfig", "returns", "a", "NetworkDB", "config", "with", "default", "values" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/networkdb/networkdb.go#L225-L236
22,636
docker/libnetwork
networkdb/networkdb.go
New
func New(c *Config) (*NetworkDB, error) { // The garbage collection logic for entries leverage the presence of the network. // For this reason the expiration time of the network is put slightly higher than the entry expiration so that // there is at least 5 extra cycle to make sure that all the entries are properly deleted before deleting the network. c.reapNetworkInterval = c.reapEntryInterval + 5*reapPeriod nDB := &NetworkDB{ config: c, indexes: make(map[int]*radix.Tree), networks: make(map[string]map[string]*network), nodes: make(map[string]*node), failedNodes: make(map[string]*node), leftNodes: make(map[string]*node), networkNodes: make(map[string][]string), bulkSyncAckTbl: make(map[string]chan struct{}), broadcaster: events.NewBroadcaster(), } nDB.indexes[byTable] = radix.New() nDB.indexes[byNetwork] = radix.New() logrus.Infof("New memberlist node - Node:%v will use memberlist nodeID:%v with config:%+v", c.Hostname, c.NodeID, c) if err := nDB.clusterInit(); err != nil { return nil, err } return nDB, nil }
go
func New(c *Config) (*NetworkDB, error) { // The garbage collection logic for entries leverage the presence of the network. // For this reason the expiration time of the network is put slightly higher than the entry expiration so that // there is at least 5 extra cycle to make sure that all the entries are properly deleted before deleting the network. c.reapNetworkInterval = c.reapEntryInterval + 5*reapPeriod nDB := &NetworkDB{ config: c, indexes: make(map[int]*radix.Tree), networks: make(map[string]map[string]*network), nodes: make(map[string]*node), failedNodes: make(map[string]*node), leftNodes: make(map[string]*node), networkNodes: make(map[string][]string), bulkSyncAckTbl: make(map[string]chan struct{}), broadcaster: events.NewBroadcaster(), } nDB.indexes[byTable] = radix.New() nDB.indexes[byNetwork] = radix.New() logrus.Infof("New memberlist node - Node:%v will use memberlist nodeID:%v with config:%+v", c.Hostname, c.NodeID, c) if err := nDB.clusterInit(); err != nil { return nil, err } return nDB, nil }
[ "func", "New", "(", "c", "*", "Config", ")", "(", "*", "NetworkDB", ",", "error", ")", "{", "// The garbage collection logic for entries leverage the presence of the network.", "// For this reason the expiration time of the network is put slightly higher than the entry expiration so that", "// there is at least 5 extra cycle to make sure that all the entries are properly deleted before deleting the network.", "c", ".", "reapNetworkInterval", "=", "c", ".", "reapEntryInterval", "+", "5", "*", "reapPeriod", "\n\n", "nDB", ":=", "&", "NetworkDB", "{", "config", ":", "c", ",", "indexes", ":", "make", "(", "map", "[", "int", "]", "*", "radix", ".", "Tree", ")", ",", "networks", ":", "make", "(", "map", "[", "string", "]", "map", "[", "string", "]", "*", "network", ")", ",", "nodes", ":", "make", "(", "map", "[", "string", "]", "*", "node", ")", ",", "failedNodes", ":", "make", "(", "map", "[", "string", "]", "*", "node", ")", ",", "leftNodes", ":", "make", "(", "map", "[", "string", "]", "*", "node", ")", ",", "networkNodes", ":", "make", "(", "map", "[", "string", "]", "[", "]", "string", ")", ",", "bulkSyncAckTbl", ":", "make", "(", "map", "[", "string", "]", "chan", "struct", "{", "}", ")", ",", "broadcaster", ":", "events", ".", "NewBroadcaster", "(", ")", ",", "}", "\n\n", "nDB", ".", "indexes", "[", "byTable", "]", "=", "radix", ".", "New", "(", ")", "\n", "nDB", ".", "indexes", "[", "byNetwork", "]", "=", "radix", ".", "New", "(", ")", "\n\n", "logrus", ".", "Infof", "(", "\"", "\"", ",", "c", ".", "Hostname", ",", "c", ".", "NodeID", ",", "c", ")", "\n", "if", "err", ":=", "nDB", ".", "clusterInit", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "nDB", ",", "nil", "\n", "}" ]
// New creates a new instance of NetworkDB using the Config passed by // the caller.
[ "New", "creates", "a", "new", "instance", "of", "NetworkDB", "using", "the", "Config", "passed", "by", "the", "caller", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/networkdb/networkdb.go#L240-L267
22,637
docker/libnetwork
networkdb/networkdb.go
Close
func (nDB *NetworkDB) Close() { if err := nDB.clusterLeave(); err != nil { logrus.Errorf("%v(%v) Could not close DB: %v", nDB.config.Hostname, nDB.config.NodeID, err) } //Avoid (*Broadcaster).run goroutine leak nDB.broadcaster.Close() }
go
func (nDB *NetworkDB) Close() { if err := nDB.clusterLeave(); err != nil { logrus.Errorf("%v(%v) Could not close DB: %v", nDB.config.Hostname, nDB.config.NodeID, err) } //Avoid (*Broadcaster).run goroutine leak nDB.broadcaster.Close() }
[ "func", "(", "nDB", "*", "NetworkDB", ")", "Close", "(", ")", "{", "if", "err", ":=", "nDB", ".", "clusterLeave", "(", ")", ";", "err", "!=", "nil", "{", "logrus", ".", "Errorf", "(", "\"", "\"", ",", "nDB", ".", "config", ".", "Hostname", ",", "nDB", ".", "config", ".", "NodeID", ",", "err", ")", "\n", "}", "\n\n", "//Avoid (*Broadcaster).run goroutine leak", "nDB", ".", "broadcaster", ".", "Close", "(", ")", "\n", "}" ]
// Close destroys this NetworkDB instance by leave the cluster, // stopping timers, canceling goroutines etc.
[ "Close", "destroys", "this", "NetworkDB", "instance", "by", "leave", "the", "cluster", "stopping", "timers", "canceling", "goroutines", "etc", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/networkdb/networkdb.go#L281-L288
22,638
docker/libnetwork
networkdb/networkdb.go
ClusterPeers
func (nDB *NetworkDB) ClusterPeers() []PeerInfo { nDB.RLock() defer nDB.RUnlock() peers := make([]PeerInfo, 0, len(nDB.nodes)) for _, node := range nDB.nodes { peers = append(peers, PeerInfo{ Name: node.Name, IP: node.Node.Addr.String(), }) } return peers }
go
func (nDB *NetworkDB) ClusterPeers() []PeerInfo { nDB.RLock() defer nDB.RUnlock() peers := make([]PeerInfo, 0, len(nDB.nodes)) for _, node := range nDB.nodes { peers = append(peers, PeerInfo{ Name: node.Name, IP: node.Node.Addr.String(), }) } return peers }
[ "func", "(", "nDB", "*", "NetworkDB", ")", "ClusterPeers", "(", ")", "[", "]", "PeerInfo", "{", "nDB", ".", "RLock", "(", ")", "\n", "defer", "nDB", ".", "RUnlock", "(", ")", "\n", "peers", ":=", "make", "(", "[", "]", "PeerInfo", ",", "0", ",", "len", "(", "nDB", ".", "nodes", ")", ")", "\n", "for", "_", ",", "node", ":=", "range", "nDB", ".", "nodes", "{", "peers", "=", "append", "(", "peers", ",", "PeerInfo", "{", "Name", ":", "node", ".", "Name", ",", "IP", ":", "node", ".", "Node", ".", "Addr", ".", "String", "(", ")", ",", "}", ")", "\n", "}", "\n", "return", "peers", "\n", "}" ]
// ClusterPeers returns all the gossip cluster peers.
[ "ClusterPeers", "returns", "all", "the", "gossip", "cluster", "peers", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/networkdb/networkdb.go#L291-L302
22,639
docker/libnetwork
networkdb/networkdb.go
Peers
func (nDB *NetworkDB) Peers(nid string) []PeerInfo { nDB.RLock() defer nDB.RUnlock() peers := make([]PeerInfo, 0, len(nDB.networkNodes[nid])) for _, nodeName := range nDB.networkNodes[nid] { if node, ok := nDB.nodes[nodeName]; ok { peers = append(peers, PeerInfo{ Name: node.Name, IP: node.Addr.String(), }) } else { // Added for testing purposes, this condition should never happen else mean that the network list // is out of sync with the node list peers = append(peers, PeerInfo{Name: nodeName, IP: "unknown"}) } } return peers }
go
func (nDB *NetworkDB) Peers(nid string) []PeerInfo { nDB.RLock() defer nDB.RUnlock() peers := make([]PeerInfo, 0, len(nDB.networkNodes[nid])) for _, nodeName := range nDB.networkNodes[nid] { if node, ok := nDB.nodes[nodeName]; ok { peers = append(peers, PeerInfo{ Name: node.Name, IP: node.Addr.String(), }) } else { // Added for testing purposes, this condition should never happen else mean that the network list // is out of sync with the node list peers = append(peers, PeerInfo{Name: nodeName, IP: "unknown"}) } } return peers }
[ "func", "(", "nDB", "*", "NetworkDB", ")", "Peers", "(", "nid", "string", ")", "[", "]", "PeerInfo", "{", "nDB", ".", "RLock", "(", ")", "\n", "defer", "nDB", ".", "RUnlock", "(", ")", "\n", "peers", ":=", "make", "(", "[", "]", "PeerInfo", ",", "0", ",", "len", "(", "nDB", ".", "networkNodes", "[", "nid", "]", ")", ")", "\n", "for", "_", ",", "nodeName", ":=", "range", "nDB", ".", "networkNodes", "[", "nid", "]", "{", "if", "node", ",", "ok", ":=", "nDB", ".", "nodes", "[", "nodeName", "]", ";", "ok", "{", "peers", "=", "append", "(", "peers", ",", "PeerInfo", "{", "Name", ":", "node", ".", "Name", ",", "IP", ":", "node", ".", "Addr", ".", "String", "(", ")", ",", "}", ")", "\n", "}", "else", "{", "// Added for testing purposes, this condition should never happen else mean that the network list", "// is out of sync with the node list", "peers", "=", "append", "(", "peers", ",", "PeerInfo", "{", "Name", ":", "nodeName", ",", "IP", ":", "\"", "\"", "}", ")", "\n", "}", "\n", "}", "\n", "return", "peers", "\n", "}" ]
// Peers returns the gossip peers for a given network.
[ "Peers", "returns", "the", "gossip", "peers", "for", "a", "given", "network", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/networkdb/networkdb.go#L305-L322
22,640
docker/libnetwork
networkdb/networkdb.go
GetTableByNetwork
func (nDB *NetworkDB) GetTableByNetwork(tname, nid string) map[string]*TableElem { entries := make(map[string]*TableElem) nDB.indexes[byTable].WalkPrefix(fmt.Sprintf("/%s/%s", tname, nid), func(k string, v interface{}) bool { entry := v.(*entry) if entry.deleting { return false } key := k[strings.LastIndex(k, "/")+1:] entries[key] = &TableElem{Value: entry.value, owner: entry.node} return false }) return entries }
go
func (nDB *NetworkDB) GetTableByNetwork(tname, nid string) map[string]*TableElem { entries := make(map[string]*TableElem) nDB.indexes[byTable].WalkPrefix(fmt.Sprintf("/%s/%s", tname, nid), func(k string, v interface{}) bool { entry := v.(*entry) if entry.deleting { return false } key := k[strings.LastIndex(k, "/")+1:] entries[key] = &TableElem{Value: entry.value, owner: entry.node} return false }) return entries }
[ "func", "(", "nDB", "*", "NetworkDB", ")", "GetTableByNetwork", "(", "tname", ",", "nid", "string", ")", "map", "[", "string", "]", "*", "TableElem", "{", "entries", ":=", "make", "(", "map", "[", "string", "]", "*", "TableElem", ")", "\n", "nDB", ".", "indexes", "[", "byTable", "]", ".", "WalkPrefix", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "tname", ",", "nid", ")", ",", "func", "(", "k", "string", ",", "v", "interface", "{", "}", ")", "bool", "{", "entry", ":=", "v", ".", "(", "*", "entry", ")", "\n", "if", "entry", ".", "deleting", "{", "return", "false", "\n", "}", "\n", "key", ":=", "k", "[", "strings", ".", "LastIndex", "(", "k", ",", "\"", "\"", ")", "+", "1", ":", "]", "\n", "entries", "[", "key", "]", "=", "&", "TableElem", "{", "Value", ":", "entry", ".", "value", ",", "owner", ":", "entry", ".", "node", "}", "\n", "return", "false", "\n", "}", ")", "\n", "return", "entries", "\n", "}" ]
// GetTableByNetwork walks the networkdb by the give table and network id and // returns a map of keys and values
[ "GetTableByNetwork", "walks", "the", "networkdb", "by", "the", "give", "table", "and", "network", "id", "and", "returns", "a", "map", "of", "keys", "and", "values" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/networkdb/networkdb.go#L413-L425
22,641
docker/libnetwork
networkdb/networkdb.go
WalkTable
func (nDB *NetworkDB) WalkTable(tname string, fn func(string, string, []byte, bool) bool) error { nDB.RLock() values := make(map[string]interface{}) nDB.indexes[byTable].WalkPrefix(fmt.Sprintf("/%s", tname), func(path string, v interface{}) bool { values[path] = v return false }) nDB.RUnlock() for k, v := range values { params := strings.Split(k[1:], "/") nid := params[1] key := params[2] if fn(nid, key, v.(*entry).value, v.(*entry).deleting) { return nil } } return nil }
go
func (nDB *NetworkDB) WalkTable(tname string, fn func(string, string, []byte, bool) bool) error { nDB.RLock() values := make(map[string]interface{}) nDB.indexes[byTable].WalkPrefix(fmt.Sprintf("/%s", tname), func(path string, v interface{}) bool { values[path] = v return false }) nDB.RUnlock() for k, v := range values { params := strings.Split(k[1:], "/") nid := params[1] key := params[2] if fn(nid, key, v.(*entry).value, v.(*entry).deleting) { return nil } } return nil }
[ "func", "(", "nDB", "*", "NetworkDB", ")", "WalkTable", "(", "tname", "string", ",", "fn", "func", "(", "string", ",", "string", ",", "[", "]", "byte", ",", "bool", ")", "bool", ")", "error", "{", "nDB", ".", "RLock", "(", ")", "\n", "values", ":=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "nDB", ".", "indexes", "[", "byTable", "]", ".", "WalkPrefix", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "tname", ")", ",", "func", "(", "path", "string", ",", "v", "interface", "{", "}", ")", "bool", "{", "values", "[", "path", "]", "=", "v", "\n", "return", "false", "\n", "}", ")", "\n", "nDB", ".", "RUnlock", "(", ")", "\n\n", "for", "k", ",", "v", ":=", "range", "values", "{", "params", ":=", "strings", ".", "Split", "(", "k", "[", "1", ":", "]", ",", "\"", "\"", ")", "\n", "nid", ":=", "params", "[", "1", "]", "\n", "key", ":=", "params", "[", "2", "]", "\n", "if", "fn", "(", "nid", ",", "key", ",", "v", ".", "(", "*", "entry", ")", ".", "value", ",", "v", ".", "(", "*", "entry", ")", ".", "deleting", ")", "{", "return", "nil", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// WalkTable walks a single table in NetworkDB and invokes the passed // function for each entry in the table passing the network, key, // value. The walk stops if the passed function returns a true.
[ "WalkTable", "walks", "a", "single", "table", "in", "NetworkDB", "and", "invokes", "the", "passed", "function", "for", "each", "entry", "in", "the", "table", "passing", "the", "network", "key", "value", ".", "The", "walk", "stops", "if", "the", "passed", "function", "returns", "a", "true", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/networkdb/networkdb.go#L569-L588
22,642
docker/libnetwork
networkdb/networkdb.go
JoinNetwork
func (nDB *NetworkDB) JoinNetwork(nid string) error { ltime := nDB.networkClock.Increment() nDB.Lock() nodeNetworks, ok := nDB.networks[nDB.config.NodeID] if !ok { nodeNetworks = make(map[string]*network) nDB.networks[nDB.config.NodeID] = nodeNetworks } n, ok := nodeNetworks[nid] var entries int if ok { entries = n.entriesNumber } nodeNetworks[nid] = &network{id: nid, ltime: ltime, entriesNumber: entries} nodeNetworks[nid].tableBroadcasts = &memberlist.TransmitLimitedQueue{ NumNodes: func() int { //TODO fcrisciani this can be optimized maybe avoiding the lock? // this call is done each GetBroadcasts call to evaluate the number of // replicas for the message nDB.RLock() defer nDB.RUnlock() return len(nDB.networkNodes[nid]) }, RetransmitMult: 4, } nDB.addNetworkNode(nid, nDB.config.NodeID) networkNodes := nDB.networkNodes[nid] n = nodeNetworks[nid] nDB.Unlock() if err := nDB.sendNetworkEvent(nid, NetworkEventTypeJoin, ltime); err != nil { return fmt.Errorf("failed to send leave network event for %s: %v", nid, err) } logrus.Debugf("%v(%v): joined network %s", nDB.config.Hostname, nDB.config.NodeID, nid) if _, err := nDB.bulkSync(networkNodes, true); err != nil { logrus.Errorf("Error bulk syncing while joining network %s: %v", nid, err) } // Mark the network as being synced // note this is a best effort, we are not checking the result of the bulk sync nDB.Lock() n.inSync = true nDB.Unlock() return nil }
go
func (nDB *NetworkDB) JoinNetwork(nid string) error { ltime := nDB.networkClock.Increment() nDB.Lock() nodeNetworks, ok := nDB.networks[nDB.config.NodeID] if !ok { nodeNetworks = make(map[string]*network) nDB.networks[nDB.config.NodeID] = nodeNetworks } n, ok := nodeNetworks[nid] var entries int if ok { entries = n.entriesNumber } nodeNetworks[nid] = &network{id: nid, ltime: ltime, entriesNumber: entries} nodeNetworks[nid].tableBroadcasts = &memberlist.TransmitLimitedQueue{ NumNodes: func() int { //TODO fcrisciani this can be optimized maybe avoiding the lock? // this call is done each GetBroadcasts call to evaluate the number of // replicas for the message nDB.RLock() defer nDB.RUnlock() return len(nDB.networkNodes[nid]) }, RetransmitMult: 4, } nDB.addNetworkNode(nid, nDB.config.NodeID) networkNodes := nDB.networkNodes[nid] n = nodeNetworks[nid] nDB.Unlock() if err := nDB.sendNetworkEvent(nid, NetworkEventTypeJoin, ltime); err != nil { return fmt.Errorf("failed to send leave network event for %s: %v", nid, err) } logrus.Debugf("%v(%v): joined network %s", nDB.config.Hostname, nDB.config.NodeID, nid) if _, err := nDB.bulkSync(networkNodes, true); err != nil { logrus.Errorf("Error bulk syncing while joining network %s: %v", nid, err) } // Mark the network as being synced // note this is a best effort, we are not checking the result of the bulk sync nDB.Lock() n.inSync = true nDB.Unlock() return nil }
[ "func", "(", "nDB", "*", "NetworkDB", ")", "JoinNetwork", "(", "nid", "string", ")", "error", "{", "ltime", ":=", "nDB", ".", "networkClock", ".", "Increment", "(", ")", "\n\n", "nDB", ".", "Lock", "(", ")", "\n", "nodeNetworks", ",", "ok", ":=", "nDB", ".", "networks", "[", "nDB", ".", "config", ".", "NodeID", "]", "\n", "if", "!", "ok", "{", "nodeNetworks", "=", "make", "(", "map", "[", "string", "]", "*", "network", ")", "\n", "nDB", ".", "networks", "[", "nDB", ".", "config", ".", "NodeID", "]", "=", "nodeNetworks", "\n", "}", "\n", "n", ",", "ok", ":=", "nodeNetworks", "[", "nid", "]", "\n", "var", "entries", "int", "\n", "if", "ok", "{", "entries", "=", "n", ".", "entriesNumber", "\n", "}", "\n", "nodeNetworks", "[", "nid", "]", "=", "&", "network", "{", "id", ":", "nid", ",", "ltime", ":", "ltime", ",", "entriesNumber", ":", "entries", "}", "\n", "nodeNetworks", "[", "nid", "]", ".", "tableBroadcasts", "=", "&", "memberlist", ".", "TransmitLimitedQueue", "{", "NumNodes", ":", "func", "(", ")", "int", "{", "//TODO fcrisciani this can be optimized maybe avoiding the lock?", "// this call is done each GetBroadcasts call to evaluate the number of", "// replicas for the message", "nDB", ".", "RLock", "(", ")", "\n", "defer", "nDB", ".", "RUnlock", "(", ")", "\n", "return", "len", "(", "nDB", ".", "networkNodes", "[", "nid", "]", ")", "\n", "}", ",", "RetransmitMult", ":", "4", ",", "}", "\n", "nDB", ".", "addNetworkNode", "(", "nid", ",", "nDB", ".", "config", ".", "NodeID", ")", "\n", "networkNodes", ":=", "nDB", ".", "networkNodes", "[", "nid", "]", "\n", "n", "=", "nodeNetworks", "[", "nid", "]", "\n", "nDB", ".", "Unlock", "(", ")", "\n\n", "if", "err", ":=", "nDB", ".", "sendNetworkEvent", "(", "nid", ",", "NetworkEventTypeJoin", ",", "ltime", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "nid", ",", "err", ")", "\n", "}", "\n\n", "logrus", ".", "Debugf", "(", "\"", "\"", ",", "nDB", ".", "config", ".", "Hostname", ",", "nDB", ".", "config", ".", "NodeID", ",", "nid", ")", "\n", "if", "_", ",", "err", ":=", "nDB", ".", "bulkSync", "(", "networkNodes", ",", "true", ")", ";", "err", "!=", "nil", "{", "logrus", ".", "Errorf", "(", "\"", "\"", ",", "nid", ",", "err", ")", "\n", "}", "\n\n", "// Mark the network as being synced", "// note this is a best effort, we are not checking the result of the bulk sync", "nDB", ".", "Lock", "(", ")", "\n", "n", ".", "inSync", "=", "true", "\n", "nDB", ".", "Unlock", "(", ")", "\n\n", "return", "nil", "\n", "}" ]
// JoinNetwork joins this node to a given network and propagates this // event across the cluster. This triggers this node joining the // sub-cluster of this network and participates in the network-scoped // gossip and bulk sync for this network.
[ "JoinNetwork", "joins", "this", "node", "to", "a", "given", "network", "and", "propagates", "this", "event", "across", "the", "cluster", ".", "This", "triggers", "this", "node", "joining", "the", "sub", "-", "cluster", "of", "this", "network", "and", "participates", "in", "the", "network", "-", "scoped", "gossip", "and", "bulk", "sync", "for", "this", "network", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/networkdb/networkdb.go#L594-L641
22,643
docker/libnetwork
networkdb/networkdb.go
LeaveNetwork
func (nDB *NetworkDB) LeaveNetwork(nid string) error { ltime := nDB.networkClock.Increment() if err := nDB.sendNetworkEvent(nid, NetworkEventTypeLeave, ltime); err != nil { return fmt.Errorf("failed to send leave network event for %s: %v", nid, err) } nDB.Lock() defer nDB.Unlock() // Remove myself from the list of the nodes participating to the network nDB.deleteNetworkNode(nid, nDB.config.NodeID) // Update all the local entries marking them for deletion and delete all the remote entries nDB.deleteNodeNetworkEntries(nid, nDB.config.NodeID) nodeNetworks, ok := nDB.networks[nDB.config.NodeID] if !ok { return fmt.Errorf("could not find self node for network %s while trying to leave", nid) } n, ok := nodeNetworks[nid] if !ok { return fmt.Errorf("could not find network %s while trying to leave", nid) } logrus.Debugf("%v(%v): leaving network %s", nDB.config.Hostname, nDB.config.NodeID, nid) n.ltime = ltime n.reapTime = nDB.config.reapNetworkInterval n.leaving = true return nil }
go
func (nDB *NetworkDB) LeaveNetwork(nid string) error { ltime := nDB.networkClock.Increment() if err := nDB.sendNetworkEvent(nid, NetworkEventTypeLeave, ltime); err != nil { return fmt.Errorf("failed to send leave network event for %s: %v", nid, err) } nDB.Lock() defer nDB.Unlock() // Remove myself from the list of the nodes participating to the network nDB.deleteNetworkNode(nid, nDB.config.NodeID) // Update all the local entries marking them for deletion and delete all the remote entries nDB.deleteNodeNetworkEntries(nid, nDB.config.NodeID) nodeNetworks, ok := nDB.networks[nDB.config.NodeID] if !ok { return fmt.Errorf("could not find self node for network %s while trying to leave", nid) } n, ok := nodeNetworks[nid] if !ok { return fmt.Errorf("could not find network %s while trying to leave", nid) } logrus.Debugf("%v(%v): leaving network %s", nDB.config.Hostname, nDB.config.NodeID, nid) n.ltime = ltime n.reapTime = nDB.config.reapNetworkInterval n.leaving = true return nil }
[ "func", "(", "nDB", "*", "NetworkDB", ")", "LeaveNetwork", "(", "nid", "string", ")", "error", "{", "ltime", ":=", "nDB", ".", "networkClock", ".", "Increment", "(", ")", "\n", "if", "err", ":=", "nDB", ".", "sendNetworkEvent", "(", "nid", ",", "NetworkEventTypeLeave", ",", "ltime", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "nid", ",", "err", ")", "\n", "}", "\n\n", "nDB", ".", "Lock", "(", ")", "\n", "defer", "nDB", ".", "Unlock", "(", ")", "\n\n", "// Remove myself from the list of the nodes participating to the network", "nDB", ".", "deleteNetworkNode", "(", "nid", ",", "nDB", ".", "config", ".", "NodeID", ")", "\n\n", "// Update all the local entries marking them for deletion and delete all the remote entries", "nDB", ".", "deleteNodeNetworkEntries", "(", "nid", ",", "nDB", ".", "config", ".", "NodeID", ")", "\n\n", "nodeNetworks", ",", "ok", ":=", "nDB", ".", "networks", "[", "nDB", ".", "config", ".", "NodeID", "]", "\n", "if", "!", "ok", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "nid", ")", "\n", "}", "\n\n", "n", ",", "ok", ":=", "nodeNetworks", "[", "nid", "]", "\n", "if", "!", "ok", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "nid", ")", "\n", "}", "\n\n", "logrus", ".", "Debugf", "(", "\"", "\"", ",", "nDB", ".", "config", ".", "Hostname", ",", "nDB", ".", "config", ".", "NodeID", ",", "nid", ")", "\n", "n", ".", "ltime", "=", "ltime", "\n", "n", ".", "reapTime", "=", "nDB", ".", "config", ".", "reapNetworkInterval", "\n", "n", ".", "leaving", "=", "true", "\n", "return", "nil", "\n", "}" ]
// LeaveNetwork leaves this node from a given network and propagates // this event across the cluster. This triggers this node leaving the // sub-cluster of this network and as a result will no longer // participate in the network-scoped gossip and bulk sync for this // network. Also remove all the table entries for this network from // networkdb
[ "LeaveNetwork", "leaves", "this", "node", "from", "a", "given", "network", "and", "propagates", "this", "event", "across", "the", "cluster", ".", "This", "triggers", "this", "node", "leaving", "the", "sub", "-", "cluster", "of", "this", "network", "and", "as", "a", "result", "will", "no", "longer", "participate", "in", "the", "network", "-", "scoped", "gossip", "and", "bulk", "sync", "for", "this", "network", ".", "Also", "remove", "all", "the", "table", "entries", "for", "this", "network", "from", "networkdb" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/networkdb/networkdb.go#L649-L679
22,644
docker/libnetwork
networkdb/networkdb.go
addNetworkNode
func (nDB *NetworkDB) addNetworkNode(nid string, nodeName string) { nodes := nDB.networkNodes[nid] for _, node := range nodes { if node == nodeName { return } } nDB.networkNodes[nid] = append(nDB.networkNodes[nid], nodeName) }
go
func (nDB *NetworkDB) addNetworkNode(nid string, nodeName string) { nodes := nDB.networkNodes[nid] for _, node := range nodes { if node == nodeName { return } } nDB.networkNodes[nid] = append(nDB.networkNodes[nid], nodeName) }
[ "func", "(", "nDB", "*", "NetworkDB", ")", "addNetworkNode", "(", "nid", "string", ",", "nodeName", "string", ")", "{", "nodes", ":=", "nDB", ".", "networkNodes", "[", "nid", "]", "\n", "for", "_", ",", "node", ":=", "range", "nodes", "{", "if", "node", "==", "nodeName", "{", "return", "\n", "}", "\n", "}", "\n\n", "nDB", ".", "networkNodes", "[", "nid", "]", "=", "append", "(", "nDB", ".", "networkNodes", "[", "nid", "]", ",", "nodeName", ")", "\n", "}" ]
// addNetworkNode adds the node to the list of nodes which participate // in the passed network only if it is not already present. Caller // should hold the NetworkDB lock while calling this
[ "addNetworkNode", "adds", "the", "node", "to", "the", "list", "of", "nodes", "which", "participate", "in", "the", "passed", "network", "only", "if", "it", "is", "not", "already", "present", ".", "Caller", "should", "hold", "the", "NetworkDB", "lock", "while", "calling", "this" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/networkdb/networkdb.go#L684-L693
22,645
docker/libnetwork
networkdb/networkdb.go
deleteNetworkNode
func (nDB *NetworkDB) deleteNetworkNode(nid string, nodeName string) { nodes, ok := nDB.networkNodes[nid] if !ok || len(nodes) == 0 { return } newNodes := make([]string, 0, len(nodes)-1) for _, name := range nodes { if name == nodeName { continue } newNodes = append(newNodes, name) } nDB.networkNodes[nid] = newNodes }
go
func (nDB *NetworkDB) deleteNetworkNode(nid string, nodeName string) { nodes, ok := nDB.networkNodes[nid] if !ok || len(nodes) == 0 { return } newNodes := make([]string, 0, len(nodes)-1) for _, name := range nodes { if name == nodeName { continue } newNodes = append(newNodes, name) } nDB.networkNodes[nid] = newNodes }
[ "func", "(", "nDB", "*", "NetworkDB", ")", "deleteNetworkNode", "(", "nid", "string", ",", "nodeName", "string", ")", "{", "nodes", ",", "ok", ":=", "nDB", ".", "networkNodes", "[", "nid", "]", "\n", "if", "!", "ok", "||", "len", "(", "nodes", ")", "==", "0", "{", "return", "\n", "}", "\n", "newNodes", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "len", "(", "nodes", ")", "-", "1", ")", "\n", "for", "_", ",", "name", ":=", "range", "nodes", "{", "if", "name", "==", "nodeName", "{", "continue", "\n", "}", "\n", "newNodes", "=", "append", "(", "newNodes", ",", "name", ")", "\n", "}", "\n", "nDB", ".", "networkNodes", "[", "nid", "]", "=", "newNodes", "\n", "}" ]
// Deletes the node from the list of nodes which participate in the // passed network. Caller should hold the NetworkDB lock while calling // this
[ "Deletes", "the", "node", "from", "the", "list", "of", "nodes", "which", "participate", "in", "the", "passed", "network", ".", "Caller", "should", "hold", "the", "NetworkDB", "lock", "while", "calling", "this" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/networkdb/networkdb.go#L698-L711
22,646
docker/libnetwork
networkdb/networkdb.go
findCommonNetworks
func (nDB *NetworkDB) findCommonNetworks(nodeName string) []string { nDB.RLock() defer nDB.RUnlock() var networks []string for nid := range nDB.networks[nDB.config.NodeID] { if n, ok := nDB.networks[nodeName][nid]; ok { if !n.leaving { networks = append(networks, nid) } } } return networks }
go
func (nDB *NetworkDB) findCommonNetworks(nodeName string) []string { nDB.RLock() defer nDB.RUnlock() var networks []string for nid := range nDB.networks[nDB.config.NodeID] { if n, ok := nDB.networks[nodeName][nid]; ok { if !n.leaving { networks = append(networks, nid) } } } return networks }
[ "func", "(", "nDB", "*", "NetworkDB", ")", "findCommonNetworks", "(", "nodeName", "string", ")", "[", "]", "string", "{", "nDB", ".", "RLock", "(", ")", "\n", "defer", "nDB", ".", "RUnlock", "(", ")", "\n\n", "var", "networks", "[", "]", "string", "\n", "for", "nid", ":=", "range", "nDB", ".", "networks", "[", "nDB", ".", "config", ".", "NodeID", "]", "{", "if", "n", ",", "ok", ":=", "nDB", ".", "networks", "[", "nodeName", "]", "[", "nid", "]", ";", "ok", "{", "if", "!", "n", ".", "leaving", "{", "networks", "=", "append", "(", "networks", ",", "nid", ")", "\n", "}", "\n", "}", "\n", "}", "\n\n", "return", "networks", "\n", "}" ]
// findCommonnetworks find the networks that both this node and the // passed node have joined.
[ "findCommonnetworks", "find", "the", "networks", "that", "both", "this", "node", "and", "the", "passed", "node", "have", "joined", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/networkdb/networkdb.go#L715-L729
22,647
docker/libnetwork
networkdb/cluster.go
SetKey
func (nDB *NetworkDB) SetKey(key []byte) { logrus.Debugf("Adding key %.5s", hex.EncodeToString(key)) nDB.Lock() defer nDB.Unlock() for _, dbKey := range nDB.config.Keys { if bytes.Equal(key, dbKey) { return } } nDB.config.Keys = append(nDB.config.Keys, key) if nDB.keyring != nil { nDB.keyring.AddKey(key) } }
go
func (nDB *NetworkDB) SetKey(key []byte) { logrus.Debugf("Adding key %.5s", hex.EncodeToString(key)) nDB.Lock() defer nDB.Unlock() for _, dbKey := range nDB.config.Keys { if bytes.Equal(key, dbKey) { return } } nDB.config.Keys = append(nDB.config.Keys, key) if nDB.keyring != nil { nDB.keyring.AddKey(key) } }
[ "func", "(", "nDB", "*", "NetworkDB", ")", "SetKey", "(", "key", "[", "]", "byte", ")", "{", "logrus", ".", "Debugf", "(", "\"", "\"", ",", "hex", ".", "EncodeToString", "(", "key", ")", ")", "\n", "nDB", ".", "Lock", "(", ")", "\n", "defer", "nDB", ".", "Unlock", "(", ")", "\n", "for", "_", ",", "dbKey", ":=", "range", "nDB", ".", "config", ".", "Keys", "{", "if", "bytes", ".", "Equal", "(", "key", ",", "dbKey", ")", "{", "return", "\n", "}", "\n", "}", "\n", "nDB", ".", "config", ".", "Keys", "=", "append", "(", "nDB", ".", "config", ".", "Keys", ",", "key", ")", "\n", "if", "nDB", ".", "keyring", "!=", "nil", "{", "nDB", ".", "keyring", ".", "AddKey", "(", "key", ")", "\n", "}", "\n", "}" ]
// SetKey adds a new key to the key ring
[ "SetKey", "adds", "a", "new", "key", "to", "the", "key", "ring" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/networkdb/cluster.go#L57-L70
22,648
docker/libnetwork
networkdb/cluster.go
SetPrimaryKey
func (nDB *NetworkDB) SetPrimaryKey(key []byte) { logrus.Debugf("Primary Key %.5s", hex.EncodeToString(key)) nDB.RLock() defer nDB.RUnlock() for _, dbKey := range nDB.config.Keys { if bytes.Equal(key, dbKey) { if nDB.keyring != nil { nDB.keyring.UseKey(dbKey) } break } } }
go
func (nDB *NetworkDB) SetPrimaryKey(key []byte) { logrus.Debugf("Primary Key %.5s", hex.EncodeToString(key)) nDB.RLock() defer nDB.RUnlock() for _, dbKey := range nDB.config.Keys { if bytes.Equal(key, dbKey) { if nDB.keyring != nil { nDB.keyring.UseKey(dbKey) } break } } }
[ "func", "(", "nDB", "*", "NetworkDB", ")", "SetPrimaryKey", "(", "key", "[", "]", "byte", ")", "{", "logrus", ".", "Debugf", "(", "\"", "\"", ",", "hex", ".", "EncodeToString", "(", "key", ")", ")", "\n", "nDB", ".", "RLock", "(", ")", "\n", "defer", "nDB", ".", "RUnlock", "(", ")", "\n", "for", "_", ",", "dbKey", ":=", "range", "nDB", ".", "config", ".", "Keys", "{", "if", "bytes", ".", "Equal", "(", "key", ",", "dbKey", ")", "{", "if", "nDB", ".", "keyring", "!=", "nil", "{", "nDB", ".", "keyring", ".", "UseKey", "(", "dbKey", ")", "\n", "}", "\n", "break", "\n", "}", "\n", "}", "\n", "}" ]
// SetPrimaryKey sets the given key as the primary key. This should have // been added apriori through SetKey
[ "SetPrimaryKey", "sets", "the", "given", "key", "as", "the", "primary", "key", ".", "This", "should", "have", "been", "added", "apriori", "through", "SetKey" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/networkdb/cluster.go#L74-L86
22,649
docker/libnetwork
networkdb/cluster.go
RemoveKey
func (nDB *NetworkDB) RemoveKey(key []byte) { logrus.Debugf("Remove Key %.5s", hex.EncodeToString(key)) nDB.Lock() defer nDB.Unlock() for i, dbKey := range nDB.config.Keys { if bytes.Equal(key, dbKey) { nDB.config.Keys = append(nDB.config.Keys[:i], nDB.config.Keys[i+1:]...) if nDB.keyring != nil { nDB.keyring.RemoveKey(dbKey) } break } } }
go
func (nDB *NetworkDB) RemoveKey(key []byte) { logrus.Debugf("Remove Key %.5s", hex.EncodeToString(key)) nDB.Lock() defer nDB.Unlock() for i, dbKey := range nDB.config.Keys { if bytes.Equal(key, dbKey) { nDB.config.Keys = append(nDB.config.Keys[:i], nDB.config.Keys[i+1:]...) if nDB.keyring != nil { nDB.keyring.RemoveKey(dbKey) } break } } }
[ "func", "(", "nDB", "*", "NetworkDB", ")", "RemoveKey", "(", "key", "[", "]", "byte", ")", "{", "logrus", ".", "Debugf", "(", "\"", "\"", ",", "hex", ".", "EncodeToString", "(", "key", ")", ")", "\n", "nDB", ".", "Lock", "(", ")", "\n", "defer", "nDB", ".", "Unlock", "(", ")", "\n", "for", "i", ",", "dbKey", ":=", "range", "nDB", ".", "config", ".", "Keys", "{", "if", "bytes", ".", "Equal", "(", "key", ",", "dbKey", ")", "{", "nDB", ".", "config", ".", "Keys", "=", "append", "(", "nDB", ".", "config", ".", "Keys", "[", ":", "i", "]", ",", "nDB", ".", "config", ".", "Keys", "[", "i", "+", "1", ":", "]", "...", ")", "\n", "if", "nDB", ".", "keyring", "!=", "nil", "{", "nDB", ".", "keyring", ".", "RemoveKey", "(", "dbKey", ")", "\n", "}", "\n", "break", "\n", "}", "\n", "}", "\n", "}" ]
// RemoveKey removes a key from the key ring. The key being removed // can't be the primary key
[ "RemoveKey", "removes", "a", "key", "from", "the", "key", "ring", ".", "The", "key", "being", "removed", "can", "t", "be", "the", "primary", "key" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/networkdb/cluster.go#L90-L103
22,650
docker/libnetwork
networkdb/cluster.go
mRandomNodes
func (nDB *NetworkDB) mRandomNodes(m int, nodes []string) []string { n := len(nodes) mNodes := make([]string, 0, m) OUTER: // Probe up to 3*n times, with large n this is not necessary // since k << n, but with small n we want search to be // exhaustive for i := 0; i < 3*n && len(mNodes) < m; i++ { // Get random node idx := randomOffset(n) node := nodes[idx] if node == nDB.config.NodeID { continue } // Check if we have this node already for j := 0; j < len(mNodes); j++ { if node == mNodes[j] { continue OUTER } } // Append the node mNodes = append(mNodes, node) } return mNodes }
go
func (nDB *NetworkDB) mRandomNodes(m int, nodes []string) []string { n := len(nodes) mNodes := make([]string, 0, m) OUTER: // Probe up to 3*n times, with large n this is not necessary // since k << n, but with small n we want search to be // exhaustive for i := 0; i < 3*n && len(mNodes) < m; i++ { // Get random node idx := randomOffset(n) node := nodes[idx] if node == nDB.config.NodeID { continue } // Check if we have this node already for j := 0; j < len(mNodes); j++ { if node == mNodes[j] { continue OUTER } } // Append the node mNodes = append(mNodes, node) } return mNodes }
[ "func", "(", "nDB", "*", "NetworkDB", ")", "mRandomNodes", "(", "m", "int", ",", "nodes", "[", "]", "string", ")", "[", "]", "string", "{", "n", ":=", "len", "(", "nodes", ")", "\n", "mNodes", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "m", ")", "\n", "OUTER", ":", "// Probe up to 3*n times, with large n this is not necessary", "// since k << n, but with small n we want search to be", "// exhaustive", "for", "i", ":=", "0", ";", "i", "<", "3", "*", "n", "&&", "len", "(", "mNodes", ")", "<", "m", ";", "i", "++", "{", "// Get random node", "idx", ":=", "randomOffset", "(", "n", ")", "\n", "node", ":=", "nodes", "[", "idx", "]", "\n\n", "if", "node", "==", "nDB", ".", "config", ".", "NodeID", "{", "continue", "\n", "}", "\n\n", "// Check if we have this node already", "for", "j", ":=", "0", ";", "j", "<", "len", "(", "mNodes", ")", ";", "j", "++", "{", "if", "node", "==", "mNodes", "[", "j", "]", "{", "continue", "OUTER", "\n", "}", "\n", "}", "\n\n", "// Append the node", "mNodes", "=", "append", "(", "mNodes", ",", "node", ")", "\n", "}", "\n\n", "return", "mNodes", "\n", "}" ]
// mRandomNodes is used to select up to m random nodes. It is possible // that less than m nodes are returned.
[ "mRandomNodes", "is", "used", "to", "select", "up", "to", "m", "random", "nodes", ".", "It", "is", "possible", "that", "less", "than", "m", "nodes", "are", "returned", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/networkdb/cluster.go#L733-L761
22,651
docker/libnetwork
drvregistry/drvregistry.go
New
func New(lDs, gDs interface{}, dfn DriverNotifyFunc, ifn IPAMNotifyFunc, pg plugingetter.PluginGetter) (*DrvRegistry, error) { r := &DrvRegistry{ drivers: make(driverTable), ipamDrivers: make(ipamTable), dfn: dfn, ifn: ifn, pluginGetter: pg, } return r, nil }
go
func New(lDs, gDs interface{}, dfn DriverNotifyFunc, ifn IPAMNotifyFunc, pg plugingetter.PluginGetter) (*DrvRegistry, error) { r := &DrvRegistry{ drivers: make(driverTable), ipamDrivers: make(ipamTable), dfn: dfn, ifn: ifn, pluginGetter: pg, } return r, nil }
[ "func", "New", "(", "lDs", ",", "gDs", "interface", "{", "}", ",", "dfn", "DriverNotifyFunc", ",", "ifn", "IPAMNotifyFunc", ",", "pg", "plugingetter", ".", "PluginGetter", ")", "(", "*", "DrvRegistry", ",", "error", ")", "{", "r", ":=", "&", "DrvRegistry", "{", "drivers", ":", "make", "(", "driverTable", ")", ",", "ipamDrivers", ":", "make", "(", "ipamTable", ")", ",", "dfn", ":", "dfn", ",", "ifn", ":", "ifn", ",", "pluginGetter", ":", "pg", ",", "}", "\n\n", "return", "r", ",", "nil", "\n", "}" ]
// New returns a new driver registry handle.
[ "New", "returns", "a", "new", "driver", "registry", "handle", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drvregistry/drvregistry.go#L58-L68
22,652
docker/libnetwork
drvregistry/drvregistry.go
AddDriver
func (r *DrvRegistry) AddDriver(ntype string, fn InitFunc, config map[string]interface{}) error { return fn(r, config) }
go
func (r *DrvRegistry) AddDriver(ntype string, fn InitFunc, config map[string]interface{}) error { return fn(r, config) }
[ "func", "(", "r", "*", "DrvRegistry", ")", "AddDriver", "(", "ntype", "string", ",", "fn", "InitFunc", ",", "config", "map", "[", "string", "]", "interface", "{", "}", ")", "error", "{", "return", "fn", "(", "r", ",", "config", ")", "\n", "}" ]
// AddDriver adds a network driver to the registry.
[ "AddDriver", "adds", "a", "network", "driver", "to", "the", "registry", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drvregistry/drvregistry.go#L71-L73
22,653
docker/libnetwork
drvregistry/drvregistry.go
WalkIPAMs
func (r *DrvRegistry) WalkIPAMs(ifn IPAMWalkFunc) { type ipamVal struct { name string data *ipamData } r.Lock() ivl := make([]ipamVal, 0, len(r.ipamDrivers)) for k, v := range r.ipamDrivers { ivl = append(ivl, ipamVal{name: k, data: v}) } r.Unlock() for _, iv := range ivl { if ifn(iv.name, iv.data.driver, iv.data.capability) { break } } }
go
func (r *DrvRegistry) WalkIPAMs(ifn IPAMWalkFunc) { type ipamVal struct { name string data *ipamData } r.Lock() ivl := make([]ipamVal, 0, len(r.ipamDrivers)) for k, v := range r.ipamDrivers { ivl = append(ivl, ipamVal{name: k, data: v}) } r.Unlock() for _, iv := range ivl { if ifn(iv.name, iv.data.driver, iv.data.capability) { break } } }
[ "func", "(", "r", "*", "DrvRegistry", ")", "WalkIPAMs", "(", "ifn", "IPAMWalkFunc", ")", "{", "type", "ipamVal", "struct", "{", "name", "string", "\n", "data", "*", "ipamData", "\n", "}", "\n\n", "r", ".", "Lock", "(", ")", "\n", "ivl", ":=", "make", "(", "[", "]", "ipamVal", ",", "0", ",", "len", "(", "r", ".", "ipamDrivers", ")", ")", "\n", "for", "k", ",", "v", ":=", "range", "r", ".", "ipamDrivers", "{", "ivl", "=", "append", "(", "ivl", ",", "ipamVal", "{", "name", ":", "k", ",", "data", ":", "v", "}", ")", "\n", "}", "\n", "r", ".", "Unlock", "(", ")", "\n\n", "for", "_", ",", "iv", ":=", "range", "ivl", "{", "if", "ifn", "(", "iv", ".", "name", ",", "iv", ".", "data", ".", "driver", ",", "iv", ".", "data", ".", "capability", ")", "{", "break", "\n", "}", "\n", "}", "\n", "}" ]
// WalkIPAMs walks the IPAM drivers registered in the registry and invokes the passed walk function and each one of them.
[ "WalkIPAMs", "walks", "the", "IPAM", "drivers", "registered", "in", "the", "registry", "and", "invokes", "the", "passed", "walk", "function", "and", "each", "one", "of", "them", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drvregistry/drvregistry.go#L76-L94
22,654
docker/libnetwork
drvregistry/drvregistry.go
WalkDrivers
func (r *DrvRegistry) WalkDrivers(dfn DriverWalkFunc) { type driverVal struct { name string data *driverData } r.Lock() dvl := make([]driverVal, 0, len(r.drivers)) for k, v := range r.drivers { dvl = append(dvl, driverVal{name: k, data: v}) } r.Unlock() for _, dv := range dvl { if dfn(dv.name, dv.data.driver, dv.data.capability) { break } } }
go
func (r *DrvRegistry) WalkDrivers(dfn DriverWalkFunc) { type driverVal struct { name string data *driverData } r.Lock() dvl := make([]driverVal, 0, len(r.drivers)) for k, v := range r.drivers { dvl = append(dvl, driverVal{name: k, data: v}) } r.Unlock() for _, dv := range dvl { if dfn(dv.name, dv.data.driver, dv.data.capability) { break } } }
[ "func", "(", "r", "*", "DrvRegistry", ")", "WalkDrivers", "(", "dfn", "DriverWalkFunc", ")", "{", "type", "driverVal", "struct", "{", "name", "string", "\n", "data", "*", "driverData", "\n", "}", "\n\n", "r", ".", "Lock", "(", ")", "\n", "dvl", ":=", "make", "(", "[", "]", "driverVal", ",", "0", ",", "len", "(", "r", ".", "drivers", ")", ")", "\n", "for", "k", ",", "v", ":=", "range", "r", ".", "drivers", "{", "dvl", "=", "append", "(", "dvl", ",", "driverVal", "{", "name", ":", "k", ",", "data", ":", "v", "}", ")", "\n", "}", "\n", "r", ".", "Unlock", "(", ")", "\n\n", "for", "_", ",", "dv", ":=", "range", "dvl", "{", "if", "dfn", "(", "dv", ".", "name", ",", "dv", ".", "data", ".", "driver", ",", "dv", ".", "data", ".", "capability", ")", "{", "break", "\n", "}", "\n", "}", "\n", "}" ]
// WalkDrivers walks the network drivers registered in the registry and invokes the passed walk function and each one of them.
[ "WalkDrivers", "walks", "the", "network", "drivers", "registered", "in", "the", "registry", "and", "invokes", "the", "passed", "walk", "function", "and", "each", "one", "of", "them", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drvregistry/drvregistry.go#L97-L115
22,655
docker/libnetwork
drvregistry/drvregistry.go
Driver
func (r *DrvRegistry) Driver(name string) (driverapi.Driver, *driverapi.Capability) { r.Lock() defer r.Unlock() d, ok := r.drivers[name] if !ok { return nil, nil } return d.driver, &d.capability }
go
func (r *DrvRegistry) Driver(name string) (driverapi.Driver, *driverapi.Capability) { r.Lock() defer r.Unlock() d, ok := r.drivers[name] if !ok { return nil, nil } return d.driver, &d.capability }
[ "func", "(", "r", "*", "DrvRegistry", ")", "Driver", "(", "name", "string", ")", "(", "driverapi", ".", "Driver", ",", "*", "driverapi", ".", "Capability", ")", "{", "r", ".", "Lock", "(", ")", "\n", "defer", "r", ".", "Unlock", "(", ")", "\n\n", "d", ",", "ok", ":=", "r", ".", "drivers", "[", "name", "]", "\n", "if", "!", "ok", "{", "return", "nil", ",", "nil", "\n", "}", "\n\n", "return", "d", ".", "driver", ",", "&", "d", ".", "capability", "\n", "}" ]
// Driver returns the actual network driver instance and its capability which registered with the passed name.
[ "Driver", "returns", "the", "actual", "network", "driver", "instance", "and", "its", "capability", "which", "registered", "with", "the", "passed", "name", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drvregistry/drvregistry.go#L118-L128
22,656
docker/libnetwork
drvregistry/drvregistry.go
IPAM
func (r *DrvRegistry) IPAM(name string) (ipamapi.Ipam, *ipamapi.Capability) { r.Lock() defer r.Unlock() i, ok := r.ipamDrivers[name] if !ok { return nil, nil } return i.driver, i.capability }
go
func (r *DrvRegistry) IPAM(name string) (ipamapi.Ipam, *ipamapi.Capability) { r.Lock() defer r.Unlock() i, ok := r.ipamDrivers[name] if !ok { return nil, nil } return i.driver, i.capability }
[ "func", "(", "r", "*", "DrvRegistry", ")", "IPAM", "(", "name", "string", ")", "(", "ipamapi", ".", "Ipam", ",", "*", "ipamapi", ".", "Capability", ")", "{", "r", ".", "Lock", "(", ")", "\n", "defer", "r", ".", "Unlock", "(", ")", "\n\n", "i", ",", "ok", ":=", "r", ".", "ipamDrivers", "[", "name", "]", "\n", "if", "!", "ok", "{", "return", "nil", ",", "nil", "\n", "}", "\n\n", "return", "i", ".", "driver", ",", "i", ".", "capability", "\n", "}" ]
// IPAM returns the actual IPAM driver instance and its capability which registered with the passed name.
[ "IPAM", "returns", "the", "actual", "IPAM", "driver", "instance", "and", "its", "capability", "which", "registered", "with", "the", "passed", "name", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drvregistry/drvregistry.go#L131-L141
22,657
docker/libnetwork
drvregistry/drvregistry.go
IPAMDefaultAddressSpaces
func (r *DrvRegistry) IPAMDefaultAddressSpaces(name string) (string, string, error) { r.Lock() defer r.Unlock() i, ok := r.ipamDrivers[name] if !ok { return "", "", fmt.Errorf("ipam %s not found", name) } return i.defaultLocalAddressSpace, i.defaultGlobalAddressSpace, nil }
go
func (r *DrvRegistry) IPAMDefaultAddressSpaces(name string) (string, string, error) { r.Lock() defer r.Unlock() i, ok := r.ipamDrivers[name] if !ok { return "", "", fmt.Errorf("ipam %s not found", name) } return i.defaultLocalAddressSpace, i.defaultGlobalAddressSpace, nil }
[ "func", "(", "r", "*", "DrvRegistry", ")", "IPAMDefaultAddressSpaces", "(", "name", "string", ")", "(", "string", ",", "string", ",", "error", ")", "{", "r", ".", "Lock", "(", ")", "\n", "defer", "r", ".", "Unlock", "(", ")", "\n\n", "i", ",", "ok", ":=", "r", ".", "ipamDrivers", "[", "name", "]", "\n", "if", "!", "ok", "{", "return", "\"", "\"", ",", "\"", "\"", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "name", ")", "\n", "}", "\n\n", "return", "i", ".", "defaultLocalAddressSpace", ",", "i", ".", "defaultGlobalAddressSpace", ",", "nil", "\n", "}" ]
// IPAMDefaultAddressSpaces returns the default address space strings for the passed IPAM driver name.
[ "IPAMDefaultAddressSpaces", "returns", "the", "default", "address", "space", "strings", "for", "the", "passed", "IPAM", "driver", "name", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drvregistry/drvregistry.go#L144-L154
22,658
docker/libnetwork
drvregistry/drvregistry.go
RegisterDriver
func (r *DrvRegistry) RegisterDriver(ntype string, driver driverapi.Driver, capability driverapi.Capability) error { if strings.TrimSpace(ntype) == "" { return errors.New("network type string cannot be empty") } r.Lock() dd, ok := r.drivers[ntype] r.Unlock() if ok && dd.driver.IsBuiltIn() { return driverapi.ErrActiveRegistration(ntype) } if r.dfn != nil { if err := r.dfn(ntype, driver, capability); err != nil { return err } } dData := &driverData{driver, capability} r.Lock() r.drivers[ntype] = dData r.Unlock() return nil }
go
func (r *DrvRegistry) RegisterDriver(ntype string, driver driverapi.Driver, capability driverapi.Capability) error { if strings.TrimSpace(ntype) == "" { return errors.New("network type string cannot be empty") } r.Lock() dd, ok := r.drivers[ntype] r.Unlock() if ok && dd.driver.IsBuiltIn() { return driverapi.ErrActiveRegistration(ntype) } if r.dfn != nil { if err := r.dfn(ntype, driver, capability); err != nil { return err } } dData := &driverData{driver, capability} r.Lock() r.drivers[ntype] = dData r.Unlock() return nil }
[ "func", "(", "r", "*", "DrvRegistry", ")", "RegisterDriver", "(", "ntype", "string", ",", "driver", "driverapi", ".", "Driver", ",", "capability", "driverapi", ".", "Capability", ")", "error", "{", "if", "strings", ".", "TrimSpace", "(", "ntype", ")", "==", "\"", "\"", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "r", ".", "Lock", "(", ")", "\n", "dd", ",", "ok", ":=", "r", ".", "drivers", "[", "ntype", "]", "\n", "r", ".", "Unlock", "(", ")", "\n\n", "if", "ok", "&&", "dd", ".", "driver", ".", "IsBuiltIn", "(", ")", "{", "return", "driverapi", ".", "ErrActiveRegistration", "(", "ntype", ")", "\n", "}", "\n\n", "if", "r", ".", "dfn", "!=", "nil", "{", "if", "err", ":=", "r", ".", "dfn", "(", "ntype", ",", "driver", ",", "capability", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "dData", ":=", "&", "driverData", "{", "driver", ",", "capability", "}", "\n\n", "r", ".", "Lock", "(", ")", "\n", "r", ".", "drivers", "[", "ntype", "]", "=", "dData", "\n", "r", ".", "Unlock", "(", ")", "\n\n", "return", "nil", "\n", "}" ]
// RegisterDriver registers the network driver when it gets discovered.
[ "RegisterDriver", "registers", "the", "network", "driver", "when", "it", "gets", "discovered", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drvregistry/drvregistry.go#L162-L188
22,659
docker/libnetwork
drvregistry/drvregistry.go
RegisterIpamDriver
func (r *DrvRegistry) RegisterIpamDriver(name string, driver ipamapi.Ipam) error { return r.registerIpamDriver(name, driver, &ipamapi.Capability{}) }
go
func (r *DrvRegistry) RegisterIpamDriver(name string, driver ipamapi.Ipam) error { return r.registerIpamDriver(name, driver, &ipamapi.Capability{}) }
[ "func", "(", "r", "*", "DrvRegistry", ")", "RegisterIpamDriver", "(", "name", "string", ",", "driver", "ipamapi", ".", "Ipam", ")", "error", "{", "return", "r", ".", "registerIpamDriver", "(", "name", ",", "driver", ",", "&", "ipamapi", ".", "Capability", "{", "}", ")", "\n", "}" ]
// RegisterIpamDriver registers the IPAM driver discovered with default capabilities.
[ "RegisterIpamDriver", "registers", "the", "IPAM", "driver", "discovered", "with", "default", "capabilities", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drvregistry/drvregistry.go#L221-L223
22,660
docker/libnetwork
drvregistry/drvregistry.go
RegisterIpamDriverWithCapabilities
func (r *DrvRegistry) RegisterIpamDriverWithCapabilities(name string, driver ipamapi.Ipam, caps *ipamapi.Capability) error { return r.registerIpamDriver(name, driver, caps) }
go
func (r *DrvRegistry) RegisterIpamDriverWithCapabilities(name string, driver ipamapi.Ipam, caps *ipamapi.Capability) error { return r.registerIpamDriver(name, driver, caps) }
[ "func", "(", "r", "*", "DrvRegistry", ")", "RegisterIpamDriverWithCapabilities", "(", "name", "string", ",", "driver", "ipamapi", ".", "Ipam", ",", "caps", "*", "ipamapi", ".", "Capability", ")", "error", "{", "return", "r", ".", "registerIpamDriver", "(", "name", ",", "driver", ",", "caps", ")", "\n", "}" ]
// RegisterIpamDriverWithCapabilities registers the IPAM driver discovered with specified capabilities.
[ "RegisterIpamDriverWithCapabilities", "registers", "the", "IPAM", "driver", "discovered", "with", "specified", "capabilities", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drvregistry/drvregistry.go#L226-L228
22,661
docker/libnetwork
drivers/bridge/netlink_deprecated_linux.go
getIfSocket
func getIfSocket() (fd int, err error) { for _, socket := range []int{ syscall.AF_INET, syscall.AF_PACKET, syscall.AF_INET6, } { if fd, err = syscall.Socket(socket, syscall.SOCK_DGRAM, 0); err == nil { break } } if err == nil { return fd, nil } return -1, err }
go
func getIfSocket() (fd int, err error) { for _, socket := range []int{ syscall.AF_INET, syscall.AF_PACKET, syscall.AF_INET6, } { if fd, err = syscall.Socket(socket, syscall.SOCK_DGRAM, 0); err == nil { break } } if err == nil { return fd, nil } return -1, err }
[ "func", "getIfSocket", "(", ")", "(", "fd", "int", ",", "err", "error", ")", "{", "for", "_", ",", "socket", ":=", "range", "[", "]", "int", "{", "syscall", ".", "AF_INET", ",", "syscall", ".", "AF_PACKET", ",", "syscall", ".", "AF_INET6", ",", "}", "{", "if", "fd", ",", "err", "=", "syscall", ".", "Socket", "(", "socket", ",", "syscall", ".", "SOCK_DGRAM", ",", "0", ")", ";", "err", "==", "nil", "{", "break", "\n", "}", "\n", "}", "\n", "if", "err", "==", "nil", "{", "return", "fd", ",", "nil", "\n", "}", "\n", "return", "-", "1", ",", "err", "\n", "}" ]
// THIS CODE DOES NOT COMMUNICATE WITH KERNEL VIA RTNETLINK INTERFACE // IT IS HERE FOR BACKWARDS COMPATIBILITY WITH OLDER LINUX KERNELS // WHICH SHIP WITH OLDER NOT ENTIRELY FUNCTIONAL VERSION OF NETLINK
[ "THIS", "CODE", "DOES", "NOT", "COMMUNICATE", "WITH", "KERNEL", "VIA", "RTNETLINK", "INTERFACE", "IT", "IS", "HERE", "FOR", "BACKWARDS", "COMPATIBILITY", "WITH", "OLDER", "LINUX", "KERNELS", "WHICH", "SHIP", "WITH", "OLDER", "NOT", "ENTIRELY", "FUNCTIONAL", "VERSION", "OF", "NETLINK" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/bridge/netlink_deprecated_linux.go#L35-L49
22,662
docker/libnetwork
drivers/bridge/netlink_deprecated_linux.go
ioctlAddToBridge
func ioctlAddToBridge(iface, master *net.Interface) error { return ifIoctBridge(iface, master, ioctlBrAddIf) }
go
func ioctlAddToBridge(iface, master *net.Interface) error { return ifIoctBridge(iface, master, ioctlBrAddIf) }
[ "func", "ioctlAddToBridge", "(", "iface", ",", "master", "*", "net", ".", "Interface", ")", "error", "{", "return", "ifIoctBridge", "(", "iface", ",", "master", ",", "ioctlBrAddIf", ")", "\n", "}" ]
// Add a slave to a bridge device. This is more backward-compatible than // netlink.NetworkSetMaster and works on RHEL 6.
[ "Add", "a", "slave", "to", "a", "bridge", "device", ".", "This", "is", "more", "backward", "-", "compatible", "than", "netlink", ".", "NetworkSetMaster", "and", "works", "on", "RHEL", "6", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/bridge/netlink_deprecated_linux.go#L75-L77
22,663
docker/libnetwork
sandbox.go
OptionHostname
func OptionHostname(name string) SandboxOption { return func(sb *sandbox) { sb.config.hostName = name } }
go
func OptionHostname(name string) SandboxOption { return func(sb *sandbox) { sb.config.hostName = name } }
[ "func", "OptionHostname", "(", "name", "string", ")", "SandboxOption", "{", "return", "func", "(", "sb", "*", "sandbox", ")", "{", "sb", ".", "config", ".", "hostName", "=", "name", "\n", "}", "\n", "}" ]
// OptionHostname function returns an option setter for hostname option to // be passed to NewSandbox method.
[ "OptionHostname", "function", "returns", "an", "option", "setter", "for", "hostname", "option", "to", "be", "passed", "to", "NewSandbox", "method", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/sandbox.go#L1038-L1042
22,664
docker/libnetwork
sandbox.go
OptionDomainname
func OptionDomainname(name string) SandboxOption { return func(sb *sandbox) { sb.config.domainName = name } }
go
func OptionDomainname(name string) SandboxOption { return func(sb *sandbox) { sb.config.domainName = name } }
[ "func", "OptionDomainname", "(", "name", "string", ")", "SandboxOption", "{", "return", "func", "(", "sb", "*", "sandbox", ")", "{", "sb", ".", "config", ".", "domainName", "=", "name", "\n", "}", "\n", "}" ]
// OptionDomainname function returns an option setter for domainname option to // be passed to NewSandbox method.
[ "OptionDomainname", "function", "returns", "an", "option", "setter", "for", "domainname", "option", "to", "be", "passed", "to", "NewSandbox", "method", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/sandbox.go#L1046-L1050
22,665
docker/libnetwork
sandbox.go
OptionHostsPath
func OptionHostsPath(path string) SandboxOption { return func(sb *sandbox) { sb.config.hostsPath = path } }
go
func OptionHostsPath(path string) SandboxOption { return func(sb *sandbox) { sb.config.hostsPath = path } }
[ "func", "OptionHostsPath", "(", "path", "string", ")", "SandboxOption", "{", "return", "func", "(", "sb", "*", "sandbox", ")", "{", "sb", ".", "config", ".", "hostsPath", "=", "path", "\n", "}", "\n", "}" ]
// OptionHostsPath function returns an option setter for hostspath option to // be passed to NewSandbox method.
[ "OptionHostsPath", "function", "returns", "an", "option", "setter", "for", "hostspath", "option", "to", "be", "passed", "to", "NewSandbox", "method", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/sandbox.go#L1054-L1058
22,666
docker/libnetwork
sandbox.go
OptionOriginHostsPath
func OptionOriginHostsPath(path string) SandboxOption { return func(sb *sandbox) { sb.config.originHostsPath = path } }
go
func OptionOriginHostsPath(path string) SandboxOption { return func(sb *sandbox) { sb.config.originHostsPath = path } }
[ "func", "OptionOriginHostsPath", "(", "path", "string", ")", "SandboxOption", "{", "return", "func", "(", "sb", "*", "sandbox", ")", "{", "sb", ".", "config", ".", "originHostsPath", "=", "path", "\n", "}", "\n", "}" ]
// OptionOriginHostsPath function returns an option setter for origin hosts file path // to be passed to NewSandbox method.
[ "OptionOriginHostsPath", "function", "returns", "an", "option", "setter", "for", "origin", "hosts", "file", "path", "to", "be", "passed", "to", "NewSandbox", "method", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/sandbox.go#L1062-L1066
22,667
docker/libnetwork
sandbox.go
OptionParentUpdate
func OptionParentUpdate(cid string, name, ip string) SandboxOption { return func(sb *sandbox) { sb.config.parentUpdates = append(sb.config.parentUpdates, parentUpdate{cid: cid, name: name, ip: ip}) } }
go
func OptionParentUpdate(cid string, name, ip string) SandboxOption { return func(sb *sandbox) { sb.config.parentUpdates = append(sb.config.parentUpdates, parentUpdate{cid: cid, name: name, ip: ip}) } }
[ "func", "OptionParentUpdate", "(", "cid", "string", ",", "name", ",", "ip", "string", ")", "SandboxOption", "{", "return", "func", "(", "sb", "*", "sandbox", ")", "{", "sb", ".", "config", ".", "parentUpdates", "=", "append", "(", "sb", ".", "config", ".", "parentUpdates", ",", "parentUpdate", "{", "cid", ":", "cid", ",", "name", ":", "name", ",", "ip", ":", "ip", "}", ")", "\n", "}", "\n", "}" ]
// OptionParentUpdate function returns an option setter for parent container // which needs to update the IP address for the linked container.
[ "OptionParentUpdate", "function", "returns", "an", "option", "setter", "for", "parent", "container", "which", "needs", "to", "update", "the", "IP", "address", "for", "the", "linked", "container", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/sandbox.go#L1078-L1082
22,668
docker/libnetwork
sandbox.go
OptionResolvConfPath
func OptionResolvConfPath(path string) SandboxOption { return func(sb *sandbox) { sb.config.resolvConfPath = path } }
go
func OptionResolvConfPath(path string) SandboxOption { return func(sb *sandbox) { sb.config.resolvConfPath = path } }
[ "func", "OptionResolvConfPath", "(", "path", "string", ")", "SandboxOption", "{", "return", "func", "(", "sb", "*", "sandbox", ")", "{", "sb", ".", "config", ".", "resolvConfPath", "=", "path", "\n", "}", "\n", "}" ]
// OptionResolvConfPath function returns an option setter for resolvconfpath option to // be passed to net container methods.
[ "OptionResolvConfPath", "function", "returns", "an", "option", "setter", "for", "resolvconfpath", "option", "to", "be", "passed", "to", "net", "container", "methods", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/sandbox.go#L1086-L1090
22,669
docker/libnetwork
sandbox.go
OptionOriginResolvConfPath
func OptionOriginResolvConfPath(path string) SandboxOption { return func(sb *sandbox) { sb.config.originResolvConfPath = path } }
go
func OptionOriginResolvConfPath(path string) SandboxOption { return func(sb *sandbox) { sb.config.originResolvConfPath = path } }
[ "func", "OptionOriginResolvConfPath", "(", "path", "string", ")", "SandboxOption", "{", "return", "func", "(", "sb", "*", "sandbox", ")", "{", "sb", ".", "config", ".", "originResolvConfPath", "=", "path", "\n", "}", "\n", "}" ]
// OptionOriginResolvConfPath function returns an option setter to set the path to the // origin resolv.conf file to be passed to net container methods.
[ "OptionOriginResolvConfPath", "function", "returns", "an", "option", "setter", "to", "set", "the", "path", "to", "the", "origin", "resolv", ".", "conf", "file", "to", "be", "passed", "to", "net", "container", "methods", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/sandbox.go#L1094-L1098
22,670
docker/libnetwork
sandbox.go
OptionDNS
func OptionDNS(dns string) SandboxOption { return func(sb *sandbox) { sb.config.dnsList = append(sb.config.dnsList, dns) } }
go
func OptionDNS(dns string) SandboxOption { return func(sb *sandbox) { sb.config.dnsList = append(sb.config.dnsList, dns) } }
[ "func", "OptionDNS", "(", "dns", "string", ")", "SandboxOption", "{", "return", "func", "(", "sb", "*", "sandbox", ")", "{", "sb", ".", "config", ".", "dnsList", "=", "append", "(", "sb", ".", "config", ".", "dnsList", ",", "dns", ")", "\n", "}", "\n", "}" ]
// OptionDNS function returns an option setter for dns entry option to // be passed to container Create method.
[ "OptionDNS", "function", "returns", "an", "option", "setter", "for", "dns", "entry", "option", "to", "be", "passed", "to", "container", "Create", "method", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/sandbox.go#L1102-L1106
22,671
docker/libnetwork
sandbox.go
OptionDNSSearch
func OptionDNSSearch(search string) SandboxOption { return func(sb *sandbox) { sb.config.dnsSearchList = append(sb.config.dnsSearchList, search) } }
go
func OptionDNSSearch(search string) SandboxOption { return func(sb *sandbox) { sb.config.dnsSearchList = append(sb.config.dnsSearchList, search) } }
[ "func", "OptionDNSSearch", "(", "search", "string", ")", "SandboxOption", "{", "return", "func", "(", "sb", "*", "sandbox", ")", "{", "sb", ".", "config", ".", "dnsSearchList", "=", "append", "(", "sb", ".", "config", ".", "dnsSearchList", ",", "search", ")", "\n", "}", "\n", "}" ]
// OptionDNSSearch function returns an option setter for dns search entry option to // be passed to container Create method.
[ "OptionDNSSearch", "function", "returns", "an", "option", "setter", "for", "dns", "search", "entry", "option", "to", "be", "passed", "to", "container", "Create", "method", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/sandbox.go#L1110-L1114
22,672
docker/libnetwork
sandbox.go
OptionDNSOptions
func OptionDNSOptions(options string) SandboxOption { return func(sb *sandbox) { sb.config.dnsOptionsList = append(sb.config.dnsOptionsList, options) } }
go
func OptionDNSOptions(options string) SandboxOption { return func(sb *sandbox) { sb.config.dnsOptionsList = append(sb.config.dnsOptionsList, options) } }
[ "func", "OptionDNSOptions", "(", "options", "string", ")", "SandboxOption", "{", "return", "func", "(", "sb", "*", "sandbox", ")", "{", "sb", ".", "config", ".", "dnsOptionsList", "=", "append", "(", "sb", ".", "config", ".", "dnsOptionsList", ",", "options", ")", "\n", "}", "\n", "}" ]
// OptionDNSOptions function returns an option setter for dns options entry option to // be passed to container Create method.
[ "OptionDNSOptions", "function", "returns", "an", "option", "setter", "for", "dns", "options", "entry", "option", "to", "be", "passed", "to", "container", "Create", "method", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/sandbox.go#L1118-L1122
22,673
docker/libnetwork
sandbox.go
OptionGeneric
func OptionGeneric(generic map[string]interface{}) SandboxOption { return func(sb *sandbox) { if sb.config.generic == nil { sb.config.generic = make(map[string]interface{}, len(generic)) } for k, v := range generic { sb.config.generic[k] = v } } }
go
func OptionGeneric(generic map[string]interface{}) SandboxOption { return func(sb *sandbox) { if sb.config.generic == nil { sb.config.generic = make(map[string]interface{}, len(generic)) } for k, v := range generic { sb.config.generic[k] = v } } }
[ "func", "OptionGeneric", "(", "generic", "map", "[", "string", "]", "interface", "{", "}", ")", "SandboxOption", "{", "return", "func", "(", "sb", "*", "sandbox", ")", "{", "if", "sb", ".", "config", ".", "generic", "==", "nil", "{", "sb", ".", "config", ".", "generic", "=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ",", "len", "(", "generic", ")", ")", "\n", "}", "\n", "for", "k", ",", "v", ":=", "range", "generic", "{", "sb", ".", "config", ".", "generic", "[", "k", "]", "=", "v", "\n", "}", "\n", "}", "\n", "}" ]
// OptionGeneric function returns an option setter for Generic configuration // that is not managed by libNetwork but can be used by the Drivers during the call to // net container creation method. Container Labels are a good example.
[ "OptionGeneric", "function", "returns", "an", "option", "setter", "for", "Generic", "configuration", "that", "is", "not", "managed", "by", "libNetwork", "but", "can", "be", "used", "by", "the", "Drivers", "during", "the", "call", "to", "net", "container", "creation", "method", ".", "Container", "Labels", "are", "a", "good", "example", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/sandbox.go#L1143-L1152
22,674
docker/libnetwork
sandbox.go
OptionExposedPorts
func OptionExposedPorts(exposedPorts []types.TransportPort) SandboxOption { return func(sb *sandbox) { if sb.config.generic == nil { sb.config.generic = make(map[string]interface{}) } // Defensive copy eps := make([]types.TransportPort, len(exposedPorts)) copy(eps, exposedPorts) // Store endpoint label and in generic because driver needs it sb.config.exposedPorts = eps sb.config.generic[netlabel.ExposedPorts] = eps } }
go
func OptionExposedPorts(exposedPorts []types.TransportPort) SandboxOption { return func(sb *sandbox) { if sb.config.generic == nil { sb.config.generic = make(map[string]interface{}) } // Defensive copy eps := make([]types.TransportPort, len(exposedPorts)) copy(eps, exposedPorts) // Store endpoint label and in generic because driver needs it sb.config.exposedPorts = eps sb.config.generic[netlabel.ExposedPorts] = eps } }
[ "func", "OptionExposedPorts", "(", "exposedPorts", "[", "]", "types", ".", "TransportPort", ")", "SandboxOption", "{", "return", "func", "(", "sb", "*", "sandbox", ")", "{", "if", "sb", ".", "config", ".", "generic", "==", "nil", "{", "sb", ".", "config", ".", "generic", "=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "}", "\n", "// Defensive copy", "eps", ":=", "make", "(", "[", "]", "types", ".", "TransportPort", ",", "len", "(", "exposedPorts", ")", ")", "\n", "copy", "(", "eps", ",", "exposedPorts", ")", "\n", "// Store endpoint label and in generic because driver needs it", "sb", ".", "config", ".", "exposedPorts", "=", "eps", "\n", "sb", ".", "config", ".", "generic", "[", "netlabel", ".", "ExposedPorts", "]", "=", "eps", "\n", "}", "\n", "}" ]
// OptionExposedPorts function returns an option setter for the container exposed // ports option to be passed to container Create method.
[ "OptionExposedPorts", "function", "returns", "an", "option", "setter", "for", "the", "container", "exposed", "ports", "option", "to", "be", "passed", "to", "container", "Create", "method", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/sandbox.go#L1156-L1168
22,675
docker/libnetwork
sandbox.go
OptionPortMapping
func OptionPortMapping(portBindings []types.PortBinding) SandboxOption { return func(sb *sandbox) { if sb.config.generic == nil { sb.config.generic = make(map[string]interface{}) } // Store a copy of the bindings as generic data to pass to the driver pbs := make([]types.PortBinding, len(portBindings)) copy(pbs, portBindings) sb.config.generic[netlabel.PortMap] = pbs } }
go
func OptionPortMapping(portBindings []types.PortBinding) SandboxOption { return func(sb *sandbox) { if sb.config.generic == nil { sb.config.generic = make(map[string]interface{}) } // Store a copy of the bindings as generic data to pass to the driver pbs := make([]types.PortBinding, len(portBindings)) copy(pbs, portBindings) sb.config.generic[netlabel.PortMap] = pbs } }
[ "func", "OptionPortMapping", "(", "portBindings", "[", "]", "types", ".", "PortBinding", ")", "SandboxOption", "{", "return", "func", "(", "sb", "*", "sandbox", ")", "{", "if", "sb", ".", "config", ".", "generic", "==", "nil", "{", "sb", ".", "config", ".", "generic", "=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "}", "\n", "// Store a copy of the bindings as generic data to pass to the driver", "pbs", ":=", "make", "(", "[", "]", "types", ".", "PortBinding", ",", "len", "(", "portBindings", ")", ")", "\n", "copy", "(", "pbs", ",", "portBindings", ")", "\n", "sb", ".", "config", ".", "generic", "[", "netlabel", ".", "PortMap", "]", "=", "pbs", "\n", "}", "\n", "}" ]
// OptionPortMapping function returns an option setter for the mapping // ports option to be passed to container Create method.
[ "OptionPortMapping", "function", "returns", "an", "option", "setter", "for", "the", "mapping", "ports", "option", "to", "be", "passed", "to", "container", "Create", "method", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/sandbox.go#L1172-L1182
22,676
docker/libnetwork
sandbox.go
OptionIngress
func OptionIngress() SandboxOption { return func(sb *sandbox) { sb.ingress = true sb.oslTypes = append(sb.oslTypes, osl.SandboxTypeIngress) } }
go
func OptionIngress() SandboxOption { return func(sb *sandbox) { sb.ingress = true sb.oslTypes = append(sb.oslTypes, osl.SandboxTypeIngress) } }
[ "func", "OptionIngress", "(", ")", "SandboxOption", "{", "return", "func", "(", "sb", "*", "sandbox", ")", "{", "sb", ".", "ingress", "=", "true", "\n", "sb", ".", "oslTypes", "=", "append", "(", "sb", ".", "oslTypes", ",", "osl", ".", "SandboxTypeIngress", ")", "\n", "}", "\n", "}" ]
// OptionIngress function returns an option setter for marking a // sandbox as the controller's ingress sandbox.
[ "OptionIngress", "function", "returns", "an", "option", "setter", "for", "marking", "a", "sandbox", "as", "the", "controller", "s", "ingress", "sandbox", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/sandbox.go#L1186-L1191
22,677
docker/libnetwork
sandbox.go
OptionLoadBalancer
func OptionLoadBalancer(nid string) SandboxOption { return func(sb *sandbox) { sb.loadBalancerNID = nid sb.oslTypes = append(sb.oslTypes, osl.SandboxTypeLoadBalancer) } }
go
func OptionLoadBalancer(nid string) SandboxOption { return func(sb *sandbox) { sb.loadBalancerNID = nid sb.oslTypes = append(sb.oslTypes, osl.SandboxTypeLoadBalancer) } }
[ "func", "OptionLoadBalancer", "(", "nid", "string", ")", "SandboxOption", "{", "return", "func", "(", "sb", "*", "sandbox", ")", "{", "sb", ".", "loadBalancerNID", "=", "nid", "\n", "sb", ".", "oslTypes", "=", "append", "(", "sb", ".", "oslTypes", ",", "osl", ".", "SandboxTypeLoadBalancer", ")", "\n", "}", "\n", "}" ]
// OptionLoadBalancer function returns an option setter for marking a // sandbox as a load balancer sandbox.
[ "OptionLoadBalancer", "function", "returns", "an", "option", "setter", "for", "marking", "a", "sandbox", "as", "a", "load", "balancer", "sandbox", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/sandbox.go#L1195-L1200
22,678
docker/libnetwork
ns/init_linux.go
Init
func Init() { var err error initNs, err = netns.Get() if err != nil { logrus.Errorf("could not get initial namespace: %v", err) } initNl, err = netlink.NewHandle(getSupportedNlFamilies()...) if err != nil { logrus.Errorf("could not create netlink handle on initial namespace: %v", err) } err = initNl.SetSocketTimeout(NetlinkSocketsTimeout) if err != nil { logrus.Warnf("Failed to set the timeout on the default netlink handle sockets: %v", err) } }
go
func Init() { var err error initNs, err = netns.Get() if err != nil { logrus.Errorf("could not get initial namespace: %v", err) } initNl, err = netlink.NewHandle(getSupportedNlFamilies()...) if err != nil { logrus.Errorf("could not create netlink handle on initial namespace: %v", err) } err = initNl.SetSocketTimeout(NetlinkSocketsTimeout) if err != nil { logrus.Warnf("Failed to set the timeout on the default netlink handle sockets: %v", err) } }
[ "func", "Init", "(", ")", "{", "var", "err", "error", "\n", "initNs", ",", "err", "=", "netns", ".", "Get", "(", ")", "\n", "if", "err", "!=", "nil", "{", "logrus", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "initNl", ",", "err", "=", "netlink", ".", "NewHandle", "(", "getSupportedNlFamilies", "(", ")", "...", ")", "\n", "if", "err", "!=", "nil", "{", "logrus", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "err", "=", "initNl", ".", "SetSocketTimeout", "(", "NetlinkSocketsTimeout", ")", "\n", "if", "err", "!=", "nil", "{", "logrus", ".", "Warnf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "}" ]
// Init initializes a new network namespace
[ "Init", "initializes", "a", "new", "network", "namespace" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ns/init_linux.go#L26-L40
22,679
docker/libnetwork
ns/init_linux.go
SetNamespace
func SetNamespace() error { initOnce.Do(Init) if err := netns.Set(initNs); err != nil { linkInfo, linkErr := getLink() if linkErr != nil { linkInfo = linkErr.Error() } return fmt.Errorf("failed to set to initial namespace, %v, initns fd %d: %v", linkInfo, initNs, err) } return nil }
go
func SetNamespace() error { initOnce.Do(Init) if err := netns.Set(initNs); err != nil { linkInfo, linkErr := getLink() if linkErr != nil { linkInfo = linkErr.Error() } return fmt.Errorf("failed to set to initial namespace, %v, initns fd %d: %v", linkInfo, initNs, err) } return nil }
[ "func", "SetNamespace", "(", ")", "error", "{", "initOnce", ".", "Do", "(", "Init", ")", "\n", "if", "err", ":=", "netns", ".", "Set", "(", "initNs", ")", ";", "err", "!=", "nil", "{", "linkInfo", ",", "linkErr", ":=", "getLink", "(", ")", "\n", "if", "linkErr", "!=", "nil", "{", "linkInfo", "=", "linkErr", ".", "Error", "(", ")", "\n", "}", "\n", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "linkInfo", ",", "initNs", ",", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// SetNamespace sets the initial namespace handler
[ "SetNamespace", "sets", "the", "initial", "namespace", "handler" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ns/init_linux.go#L43-L53
22,680
docker/libnetwork
osl/route_linux.go
programRoute
func (n *networkNamespace) programRoute(path string, dest *net.IPNet, nh net.IP) error { gwRoutes, err := n.nlHandle.RouteGet(nh) if err != nil { return fmt.Errorf("route for the next hop %s could not be found: %v", nh, err) } return n.nlHandle.RouteAdd(&netlink.Route{ Scope: netlink.SCOPE_UNIVERSE, LinkIndex: gwRoutes[0].LinkIndex, Gw: nh, Dst: dest, }) }
go
func (n *networkNamespace) programRoute(path string, dest *net.IPNet, nh net.IP) error { gwRoutes, err := n.nlHandle.RouteGet(nh) if err != nil { return fmt.Errorf("route for the next hop %s could not be found: %v", nh, err) } return n.nlHandle.RouteAdd(&netlink.Route{ Scope: netlink.SCOPE_UNIVERSE, LinkIndex: gwRoutes[0].LinkIndex, Gw: nh, Dst: dest, }) }
[ "func", "(", "n", "*", "networkNamespace", ")", "programRoute", "(", "path", "string", ",", "dest", "*", "net", ".", "IPNet", ",", "nh", "net", ".", "IP", ")", "error", "{", "gwRoutes", ",", "err", ":=", "n", ".", "nlHandle", ".", "RouteGet", "(", "nh", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "nh", ",", "err", ")", "\n", "}", "\n\n", "return", "n", ".", "nlHandle", ".", "RouteAdd", "(", "&", "netlink", ".", "Route", "{", "Scope", ":", "netlink", ".", "SCOPE_UNIVERSE", ",", "LinkIndex", ":", "gwRoutes", "[", "0", "]", ".", "LinkIndex", ",", "Gw", ":", "nh", ",", "Dst", ":", "dest", ",", "}", ")", "\n", "}" ]
// Program a route in to the namespace routing table.
[ "Program", "a", "route", "in", "to", "the", "namespace", "routing", "table", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/osl/route_linux.go#L114-L126
22,681
docker/libnetwork
cmd/proxy/sctp_proxy.go
NewSCTPProxy
func NewSCTPProxy(frontendAddr, backendAddr *sctp.SCTPAddr) (*SCTPProxy, error) { listener, err := sctp.ListenSCTP("sctp", frontendAddr) if err != nil { return nil, err } // If the port in frontendAddr was 0 then ListenSCTP will have a picked // a port to listen on, hence the call to Addr to get that actual port: return &SCTPProxy{ listener: listener, frontendAddr: listener.Addr().(*sctp.SCTPAddr), backendAddr: backendAddr, }, nil }
go
func NewSCTPProxy(frontendAddr, backendAddr *sctp.SCTPAddr) (*SCTPProxy, error) { listener, err := sctp.ListenSCTP("sctp", frontendAddr) if err != nil { return nil, err } // If the port in frontendAddr was 0 then ListenSCTP will have a picked // a port to listen on, hence the call to Addr to get that actual port: return &SCTPProxy{ listener: listener, frontendAddr: listener.Addr().(*sctp.SCTPAddr), backendAddr: backendAddr, }, nil }
[ "func", "NewSCTPProxy", "(", "frontendAddr", ",", "backendAddr", "*", "sctp", ".", "SCTPAddr", ")", "(", "*", "SCTPProxy", ",", "error", ")", "{", "listener", ",", "err", ":=", "sctp", ".", "ListenSCTP", "(", "\"", "\"", ",", "frontendAddr", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "// If the port in frontendAddr was 0 then ListenSCTP will have a picked", "// a port to listen on, hence the call to Addr to get that actual port:", "return", "&", "SCTPProxy", "{", "listener", ":", "listener", ",", "frontendAddr", ":", "listener", ".", "Addr", "(", ")", ".", "(", "*", "sctp", ".", "SCTPAddr", ")", ",", "backendAddr", ":", "backendAddr", ",", "}", ",", "nil", "\n", "}" ]
// NewSCTPProxy creates a new SCTPProxy.
[ "NewSCTPProxy", "creates", "a", "new", "SCTPProxy", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/cmd/proxy/sctp_proxy.go#L21-L33
22,682
docker/libnetwork
cmd/proxy/sctp_proxy.go
Run
func (proxy *SCTPProxy) Run() { quit := make(chan bool) defer close(quit) for { client, err := proxy.listener.Accept() if err != nil { log.Printf("Stopping proxy on sctp/%v for sctp/%v (%s)", proxy.frontendAddr, proxy.backendAddr, err) return } go proxy.clientLoop(client.(*sctp.SCTPConn), quit) } }
go
func (proxy *SCTPProxy) Run() { quit := make(chan bool) defer close(quit) for { client, err := proxy.listener.Accept() if err != nil { log.Printf("Stopping proxy on sctp/%v for sctp/%v (%s)", proxy.frontendAddr, proxy.backendAddr, err) return } go proxy.clientLoop(client.(*sctp.SCTPConn), quit) } }
[ "func", "(", "proxy", "*", "SCTPProxy", ")", "Run", "(", ")", "{", "quit", ":=", "make", "(", "chan", "bool", ")", "\n", "defer", "close", "(", "quit", ")", "\n", "for", "{", "client", ",", "err", ":=", "proxy", ".", "listener", ".", "Accept", "(", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Printf", "(", "\"", "\"", ",", "proxy", ".", "frontendAddr", ",", "proxy", ".", "backendAddr", ",", "err", ")", "\n", "return", "\n", "}", "\n", "go", "proxy", ".", "clientLoop", "(", "client", ".", "(", "*", "sctp", ".", "SCTPConn", ")", ",", "quit", ")", "\n", "}", "\n", "}" ]
// Run starts forwarding the traffic using SCTP.
[ "Run", "starts", "forwarding", "the", "traffic", "using", "SCTP", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/cmd/proxy/sctp_proxy.go#L73-L84
22,683
docker/libnetwork
drivers/windows/port_mapping.go
AllocatePorts
func AllocatePorts(portMapper *portmapper.PortMapper, bindings []types.PortBinding, containerIP net.IP) ([]types.PortBinding, error) { bs := make([]types.PortBinding, 0, len(bindings)) for _, c := range bindings { b := c.GetCopy() if err := allocatePort(portMapper, &b, containerIP); err != nil { // On allocation failure, release previously allocated ports. On cleanup error, just log a warning message if cuErr := ReleasePorts(portMapper, bs); cuErr != nil { logrus.Warnf("Upon allocation failure for %v, failed to clear previously allocated port bindings: %v", b, cuErr) } return nil, err } bs = append(bs, b) } return bs, nil }
go
func AllocatePorts(portMapper *portmapper.PortMapper, bindings []types.PortBinding, containerIP net.IP) ([]types.PortBinding, error) { bs := make([]types.PortBinding, 0, len(bindings)) for _, c := range bindings { b := c.GetCopy() if err := allocatePort(portMapper, &b, containerIP); err != nil { // On allocation failure, release previously allocated ports. On cleanup error, just log a warning message if cuErr := ReleasePorts(portMapper, bs); cuErr != nil { logrus.Warnf("Upon allocation failure for %v, failed to clear previously allocated port bindings: %v", b, cuErr) } return nil, err } bs = append(bs, b) } return bs, nil }
[ "func", "AllocatePorts", "(", "portMapper", "*", "portmapper", ".", "PortMapper", ",", "bindings", "[", "]", "types", ".", "PortBinding", ",", "containerIP", "net", ".", "IP", ")", "(", "[", "]", "types", ".", "PortBinding", ",", "error", ")", "{", "bs", ":=", "make", "(", "[", "]", "types", ".", "PortBinding", ",", "0", ",", "len", "(", "bindings", ")", ")", "\n", "for", "_", ",", "c", ":=", "range", "bindings", "{", "b", ":=", "c", ".", "GetCopy", "(", ")", "\n", "if", "err", ":=", "allocatePort", "(", "portMapper", ",", "&", "b", ",", "containerIP", ")", ";", "err", "!=", "nil", "{", "// On allocation failure, release previously allocated ports. On cleanup error, just log a warning message", "if", "cuErr", ":=", "ReleasePorts", "(", "portMapper", ",", "bs", ")", ";", "cuErr", "!=", "nil", "{", "logrus", ".", "Warnf", "(", "\"", "\"", ",", "b", ",", "cuErr", ")", "\n", "}", "\n", "return", "nil", ",", "err", "\n", "}", "\n", "bs", "=", "append", "(", "bs", ",", "b", ")", "\n", "}", "\n", "return", "bs", ",", "nil", "\n", "}" ]
// AllocatePorts allocates ports specified in bindings from the portMapper
[ "AllocatePorts", "allocates", "ports", "specified", "in", "bindings", "from", "the", "portMapper" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/windows/port_mapping.go#L29-L43
22,684
docker/libnetwork
drivers/windows/port_mapping.go
ReleasePorts
func ReleasePorts(portMapper *portmapper.PortMapper, bindings []types.PortBinding) error { var errorBuf bytes.Buffer // Attempt to release all port bindings, do not stop on failure for _, m := range bindings { if err := releasePort(portMapper, m); err != nil { errorBuf.WriteString(fmt.Sprintf("\ncould not release %v because of %v", m, err)) } } if errorBuf.Len() != 0 { return errors.New(errorBuf.String()) } return nil }
go
func ReleasePorts(portMapper *portmapper.PortMapper, bindings []types.PortBinding) error { var errorBuf bytes.Buffer // Attempt to release all port bindings, do not stop on failure for _, m := range bindings { if err := releasePort(portMapper, m); err != nil { errorBuf.WriteString(fmt.Sprintf("\ncould not release %v because of %v", m, err)) } } if errorBuf.Len() != 0 { return errors.New(errorBuf.String()) } return nil }
[ "func", "ReleasePorts", "(", "portMapper", "*", "portmapper", ".", "PortMapper", ",", "bindings", "[", "]", "types", ".", "PortBinding", ")", "error", "{", "var", "errorBuf", "bytes", ".", "Buffer", "\n\n", "// Attempt to release all port bindings, do not stop on failure", "for", "_", ",", "m", ":=", "range", "bindings", "{", "if", "err", ":=", "releasePort", "(", "portMapper", ",", "m", ")", ";", "err", "!=", "nil", "{", "errorBuf", ".", "WriteString", "(", "fmt", ".", "Sprintf", "(", "\"", "\\n", "\"", ",", "m", ",", "err", ")", ")", "\n", "}", "\n", "}", "\n\n", "if", "errorBuf", ".", "Len", "(", ")", "!=", "0", "{", "return", "errors", ".", "New", "(", "errorBuf", ".", "String", "(", ")", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// ReleasePorts releases ports specified in bindings from the portMapper
[ "ReleasePorts", "releases", "ports", "specified", "in", "bindings", "from", "the", "portMapper" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/windows/port_mapping.go#L102-L116
22,685
docker/libnetwork
api/api.go
NewHTTPHandler
func NewHTTPHandler(c libnetwork.NetworkController) func(w http.ResponseWriter, req *http.Request) { h := &httpHandler{c: c} h.initRouter() return h.handleRequest }
go
func NewHTTPHandler(c libnetwork.NetworkController) func(w http.ResponseWriter, req *http.Request) { h := &httpHandler{c: c} h.initRouter() return h.handleRequest }
[ "func", "NewHTTPHandler", "(", "c", "libnetwork", ".", "NetworkController", ")", "func", "(", "w", "http", ".", "ResponseWriter", ",", "req", "*", "http", ".", "Request", ")", "{", "h", ":=", "&", "httpHandler", "{", "c", ":", "c", "}", "\n", "h", ".", "initRouter", "(", ")", "\n", "return", "h", ".", "handleRequest", "\n", "}" ]
// NewHTTPHandler creates and initialize the HTTP handler to serve the requests for libnetwork
[ "NewHTTPHandler", "creates", "and", "initialize", "the", "HTTP", "handler", "to", "serve", "the", "requests", "for", "libnetwork" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/api/api.go#L60-L64
22,686
docker/libnetwork
networkdb/nodemgmt.go
findNode
func (nDB *NetworkDB) findNode(nodeName string) (*node, nodeState, map[string]*node) { for i, nodes := range []map[string]*node{ nDB.nodes, nDB.leftNodes, nDB.failedNodes, } { if n, ok := nodes[nodeName]; ok { return n, nodeState(i), nodes } } return nil, nodeNotFound, nil }
go
func (nDB *NetworkDB) findNode(nodeName string) (*node, nodeState, map[string]*node) { for i, nodes := range []map[string]*node{ nDB.nodes, nDB.leftNodes, nDB.failedNodes, } { if n, ok := nodes[nodeName]; ok { return n, nodeState(i), nodes } } return nil, nodeNotFound, nil }
[ "func", "(", "nDB", "*", "NetworkDB", ")", "findNode", "(", "nodeName", "string", ")", "(", "*", "node", ",", "nodeState", ",", "map", "[", "string", "]", "*", "node", ")", "{", "for", "i", ",", "nodes", ":=", "range", "[", "]", "map", "[", "string", "]", "*", "node", "{", "nDB", ".", "nodes", ",", "nDB", ".", "leftNodes", ",", "nDB", ".", "failedNodes", ",", "}", "{", "if", "n", ",", "ok", ":=", "nodes", "[", "nodeName", "]", ";", "ok", "{", "return", "n", ",", "nodeState", "(", "i", ")", ",", "nodes", "\n", "}", "\n", "}", "\n", "return", "nil", ",", "nodeNotFound", ",", "nil", "\n", "}" ]
// findNode search the node into the 3 node lists and returns the node pointer and the list // where it got found
[ "findNode", "search", "the", "node", "into", "the", "3", "node", "lists", "and", "returns", "the", "node", "pointer", "and", "the", "list", "where", "it", "got", "found" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/networkdb/nodemgmt.go#L28-L39
22,687
docker/libnetwork
networkdb/nodemgmt.go
changeNodeState
func (nDB *NetworkDB) changeNodeState(nodeName string, newState nodeState) (bool, error) { n, currState, m := nDB.findNode(nodeName) if n == nil { return false, fmt.Errorf("node %s not found", nodeName) } switch newState { case nodeActiveState: if currState == nodeActiveState { return false, nil } delete(m, nodeName) // reset the node reap time n.reapTime = 0 nDB.nodes[nodeName] = n case nodeLeftState: if currState == nodeLeftState { return false, nil } delete(m, nodeName) nDB.leftNodes[nodeName] = n case nodeFailedState: if currState == nodeFailedState { return false, nil } delete(m, nodeName) nDB.failedNodes[nodeName] = n } logrus.Infof("Node %s change state %s --> %s", nodeName, nodeStateName[currState], nodeStateName[newState]) if newState == nodeLeftState || newState == nodeFailedState { // set the node reap time, if not already set // It is possible that a node passes from failed to left and the reaptime was already set so keep that value if n.reapTime == 0 { n.reapTime = nodeReapInterval } // The node leave or fails, delete all the entries created by it. // If the node was temporary down, deleting the entries will guarantee that the CREATE events will be accepted // If the node instead left because was going down, then it makes sense to just delete all its state nDB.deleteNodeFromNetworks(n.Name) nDB.deleteNodeTableEntries(n.Name) } return true, nil }
go
func (nDB *NetworkDB) changeNodeState(nodeName string, newState nodeState) (bool, error) { n, currState, m := nDB.findNode(nodeName) if n == nil { return false, fmt.Errorf("node %s not found", nodeName) } switch newState { case nodeActiveState: if currState == nodeActiveState { return false, nil } delete(m, nodeName) // reset the node reap time n.reapTime = 0 nDB.nodes[nodeName] = n case nodeLeftState: if currState == nodeLeftState { return false, nil } delete(m, nodeName) nDB.leftNodes[nodeName] = n case nodeFailedState: if currState == nodeFailedState { return false, nil } delete(m, nodeName) nDB.failedNodes[nodeName] = n } logrus.Infof("Node %s change state %s --> %s", nodeName, nodeStateName[currState], nodeStateName[newState]) if newState == nodeLeftState || newState == nodeFailedState { // set the node reap time, if not already set // It is possible that a node passes from failed to left and the reaptime was already set so keep that value if n.reapTime == 0 { n.reapTime = nodeReapInterval } // The node leave or fails, delete all the entries created by it. // If the node was temporary down, deleting the entries will guarantee that the CREATE events will be accepted // If the node instead left because was going down, then it makes sense to just delete all its state nDB.deleteNodeFromNetworks(n.Name) nDB.deleteNodeTableEntries(n.Name) } return true, nil }
[ "func", "(", "nDB", "*", "NetworkDB", ")", "changeNodeState", "(", "nodeName", "string", ",", "newState", "nodeState", ")", "(", "bool", ",", "error", ")", "{", "n", ",", "currState", ",", "m", ":=", "nDB", ".", "findNode", "(", "nodeName", ")", "\n", "if", "n", "==", "nil", "{", "return", "false", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "nodeName", ")", "\n", "}", "\n\n", "switch", "newState", "{", "case", "nodeActiveState", ":", "if", "currState", "==", "nodeActiveState", "{", "return", "false", ",", "nil", "\n", "}", "\n\n", "delete", "(", "m", ",", "nodeName", ")", "\n", "// reset the node reap time", "n", ".", "reapTime", "=", "0", "\n", "nDB", ".", "nodes", "[", "nodeName", "]", "=", "n", "\n", "case", "nodeLeftState", ":", "if", "currState", "==", "nodeLeftState", "{", "return", "false", ",", "nil", "\n", "}", "\n\n", "delete", "(", "m", ",", "nodeName", ")", "\n", "nDB", ".", "leftNodes", "[", "nodeName", "]", "=", "n", "\n", "case", "nodeFailedState", ":", "if", "currState", "==", "nodeFailedState", "{", "return", "false", ",", "nil", "\n", "}", "\n\n", "delete", "(", "m", ",", "nodeName", ")", "\n", "nDB", ".", "failedNodes", "[", "nodeName", "]", "=", "n", "\n", "}", "\n\n", "logrus", ".", "Infof", "(", "\"", "\"", ",", "nodeName", ",", "nodeStateName", "[", "currState", "]", ",", "nodeStateName", "[", "newState", "]", ")", "\n\n", "if", "newState", "==", "nodeLeftState", "||", "newState", "==", "nodeFailedState", "{", "// set the node reap time, if not already set", "// It is possible that a node passes from failed to left and the reaptime was already set so keep that value", "if", "n", ".", "reapTime", "==", "0", "{", "n", ".", "reapTime", "=", "nodeReapInterval", "\n", "}", "\n", "// The node leave or fails, delete all the entries created by it.", "// If the node was temporary down, deleting the entries will guarantee that the CREATE events will be accepted", "// If the node instead left because was going down, then it makes sense to just delete all its state", "nDB", ".", "deleteNodeFromNetworks", "(", "n", ".", "Name", ")", "\n", "nDB", ".", "deleteNodeTableEntries", "(", "n", ".", "Name", ")", "\n", "}", "\n\n", "return", "true", ",", "nil", "\n", "}" ]
// changeNodeState changes the state of the node specified, returns true if the node was moved, // false if there was no need to change the node state. Error will be returned if the node does not // exists
[ "changeNodeState", "changes", "the", "state", "of", "the", "node", "specified", "returns", "true", "if", "the", "node", "was", "moved", "false", "if", "there", "was", "no", "need", "to", "change", "the", "node", "state", ".", "Error", "will", "be", "returned", "if", "the", "node", "does", "not", "exists" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/networkdb/nodemgmt.go#L44-L92
22,688
docker/libnetwork
networkdb/message.go
decodeCompoundMessage
func decodeCompoundMessage(buf []byte) ([][]byte, error) { var cMsg CompoundMessage if err := proto.Unmarshal(buf, &cMsg); err != nil { return nil, err } parts := make([][]byte, 0, len(cMsg.Messages)) for _, m := range cMsg.Messages { parts = append(parts, m.Payload) } return parts, nil }
go
func decodeCompoundMessage(buf []byte) ([][]byte, error) { var cMsg CompoundMessage if err := proto.Unmarshal(buf, &cMsg); err != nil { return nil, err } parts := make([][]byte, 0, len(cMsg.Messages)) for _, m := range cMsg.Messages { parts = append(parts, m.Payload) } return parts, nil }
[ "func", "decodeCompoundMessage", "(", "buf", "[", "]", "byte", ")", "(", "[", "]", "[", "]", "byte", ",", "error", ")", "{", "var", "cMsg", "CompoundMessage", "\n", "if", "err", ":=", "proto", ".", "Unmarshal", "(", "buf", ",", "&", "cMsg", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "parts", ":=", "make", "(", "[", "]", "[", "]", "byte", ",", "0", ",", "len", "(", "cMsg", ".", "Messages", ")", ")", "\n", "for", "_", ",", "m", ":=", "range", "cMsg", ".", "Messages", "{", "parts", "=", "append", "(", "parts", ",", "m", ".", "Payload", ")", "\n", "}", "\n\n", "return", "parts", ",", "nil", "\n", "}" ]
// decodeCompoundMessage splits a compound message and returns // the slices of individual messages. Returns any potential error.
[ "decodeCompoundMessage", "splits", "a", "compound", "message", "and", "returns", "the", "slices", "of", "individual", "messages", ".", "Returns", "any", "potential", "error", "." ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/networkdb/message.go#L86-L98
22,689
docker/libnetwork
bitseq/sequence.go
NewHandle
func NewHandle(app string, ds datastore.DataStore, id string, numElements uint64) (*Handle, error) { h := &Handle{ app: app, id: id, store: ds, bits: numElements, unselected: numElements, head: &sequence{ block: 0x0, count: getNumBlocks(numElements), }, } if h.store == nil { return h, nil } // Get the initial status from the ds if present. if err := h.store.GetObject(datastore.Key(h.Key()...), h); err != nil && err != datastore.ErrKeyNotFound { return nil, err } // If the handle is not in store, write it. if !h.Exists() { if err := h.writeToStore(); err != nil { return nil, fmt.Errorf("failed to write bitsequence to store: %v", err) } } return h, nil }
go
func NewHandle(app string, ds datastore.DataStore, id string, numElements uint64) (*Handle, error) { h := &Handle{ app: app, id: id, store: ds, bits: numElements, unselected: numElements, head: &sequence{ block: 0x0, count: getNumBlocks(numElements), }, } if h.store == nil { return h, nil } // Get the initial status from the ds if present. if err := h.store.GetObject(datastore.Key(h.Key()...), h); err != nil && err != datastore.ErrKeyNotFound { return nil, err } // If the handle is not in store, write it. if !h.Exists() { if err := h.writeToStore(); err != nil { return nil, fmt.Errorf("failed to write bitsequence to store: %v", err) } } return h, nil }
[ "func", "NewHandle", "(", "app", "string", ",", "ds", "datastore", ".", "DataStore", ",", "id", "string", ",", "numElements", "uint64", ")", "(", "*", "Handle", ",", "error", ")", "{", "h", ":=", "&", "Handle", "{", "app", ":", "app", ",", "id", ":", "id", ",", "store", ":", "ds", ",", "bits", ":", "numElements", ",", "unselected", ":", "numElements", ",", "head", ":", "&", "sequence", "{", "block", ":", "0x0", ",", "count", ":", "getNumBlocks", "(", "numElements", ")", ",", "}", ",", "}", "\n\n", "if", "h", ".", "store", "==", "nil", "{", "return", "h", ",", "nil", "\n", "}", "\n\n", "// Get the initial status from the ds if present.", "if", "err", ":=", "h", ".", "store", ".", "GetObject", "(", "datastore", ".", "Key", "(", "h", ".", "Key", "(", ")", "...", ")", ",", "h", ")", ";", "err", "!=", "nil", "&&", "err", "!=", "datastore", ".", "ErrKeyNotFound", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "// If the handle is not in store, write it.", "if", "!", "h", ".", "Exists", "(", ")", "{", "if", "err", ":=", "h", ".", "writeToStore", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "}", "\n\n", "return", "h", ",", "nil", "\n", "}" ]
// NewHandle returns a thread-safe instance of the bitmask handler
[ "NewHandle", "returns", "a", "thread", "-", "safe", "instance", "of", "the", "bitmask", "handler" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/bitseq/sequence.go#L50-L80
22,690
docker/libnetwork
bitseq/sequence.go
toString
func (s *sequence) toString() string { var nextBlock string if s.next == nil { nextBlock = "end" } else { nextBlock = s.next.toString() } return fmt.Sprintf("(0x%x, %d)->%s", s.block, s.count, nextBlock) }
go
func (s *sequence) toString() string { var nextBlock string if s.next == nil { nextBlock = "end" } else { nextBlock = s.next.toString() } return fmt.Sprintf("(0x%x, %d)->%s", s.block, s.count, nextBlock) }
[ "func", "(", "s", "*", "sequence", ")", "toString", "(", ")", "string", "{", "var", "nextBlock", "string", "\n", "if", "s", ".", "next", "==", "nil", "{", "nextBlock", "=", "\"", "\"", "\n", "}", "else", "{", "nextBlock", "=", "s", ".", "next", ".", "toString", "(", ")", "\n", "}", "\n", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "s", ".", "block", ",", "s", ".", "count", ",", "nextBlock", ")", "\n", "}" ]
// String returns a string representation of the block sequence starting from this block
[ "String", "returns", "a", "string", "representation", "of", "the", "block", "sequence", "starting", "from", "this", "block" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/bitseq/sequence.go#L90-L98
22,691
docker/libnetwork
bitseq/sequence.go
getAvailableBit
func (s *sequence) getAvailableBit(from uint64) (uint64, uint64, error) { if s.block == blockMAX || s.count == 0 { return invalidPos, invalidPos, ErrNoBitAvailable } bits := from bitSel := blockFirstBit >> from for bitSel > 0 && s.block&bitSel != 0 { bitSel >>= 1 bits++ } // Check if the loop exited because it could not // find any available bit int block starting from // "from". Return invalid pos in that case. if bitSel == 0 { return invalidPos, invalidPos, ErrNoBitAvailable } return bits / 8, bits % 8, nil }
go
func (s *sequence) getAvailableBit(from uint64) (uint64, uint64, error) { if s.block == blockMAX || s.count == 0 { return invalidPos, invalidPos, ErrNoBitAvailable } bits := from bitSel := blockFirstBit >> from for bitSel > 0 && s.block&bitSel != 0 { bitSel >>= 1 bits++ } // Check if the loop exited because it could not // find any available bit int block starting from // "from". Return invalid pos in that case. if bitSel == 0 { return invalidPos, invalidPos, ErrNoBitAvailable } return bits / 8, bits % 8, nil }
[ "func", "(", "s", "*", "sequence", ")", "getAvailableBit", "(", "from", "uint64", ")", "(", "uint64", ",", "uint64", ",", "error", ")", "{", "if", "s", ".", "block", "==", "blockMAX", "||", "s", ".", "count", "==", "0", "{", "return", "invalidPos", ",", "invalidPos", ",", "ErrNoBitAvailable", "\n", "}", "\n", "bits", ":=", "from", "\n", "bitSel", ":=", "blockFirstBit", ">>", "from", "\n", "for", "bitSel", ">", "0", "&&", "s", ".", "block", "&", "bitSel", "!=", "0", "{", "bitSel", ">>=", "1", "\n", "bits", "++", "\n", "}", "\n", "// Check if the loop exited because it could not", "// find any available bit int block starting from", "// \"from\". Return invalid pos in that case.", "if", "bitSel", "==", "0", "{", "return", "invalidPos", ",", "invalidPos", ",", "ErrNoBitAvailable", "\n", "}", "\n", "return", "bits", "/", "8", ",", "bits", "%", "8", ",", "nil", "\n", "}" ]
// GetAvailableBit returns the position of the first unset bit in the bitmask represented by this sequence
[ "GetAvailableBit", "returns", "the", "position", "of", "the", "first", "unset", "bit", "in", "the", "bitmask", "represented", "by", "this", "sequence" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/bitseq/sequence.go#L101-L118
22,692
docker/libnetwork
bitseq/sequence.go
getCopy
func (s *sequence) getCopy() *sequence { n := &sequence{block: s.block, count: s.count} pn := n ps := s.next for ps != nil { pn.next = &sequence{block: ps.block, count: ps.count} pn = pn.next ps = ps.next } return n }
go
func (s *sequence) getCopy() *sequence { n := &sequence{block: s.block, count: s.count} pn := n ps := s.next for ps != nil { pn.next = &sequence{block: ps.block, count: ps.count} pn = pn.next ps = ps.next } return n }
[ "func", "(", "s", "*", "sequence", ")", "getCopy", "(", ")", "*", "sequence", "{", "n", ":=", "&", "sequence", "{", "block", ":", "s", ".", "block", ",", "count", ":", "s", ".", "count", "}", "\n", "pn", ":=", "n", "\n", "ps", ":=", "s", ".", "next", "\n", "for", "ps", "!=", "nil", "{", "pn", ".", "next", "=", "&", "sequence", "{", "block", ":", "ps", ".", "block", ",", "count", ":", "ps", ".", "count", "}", "\n", "pn", "=", "pn", ".", "next", "\n", "ps", "=", "ps", ".", "next", "\n", "}", "\n", "return", "n", "\n", "}" ]
// GetCopy returns a copy of the linked list rooted at this node
[ "GetCopy", "returns", "a", "copy", "of", "the", "linked", "list", "rooted", "at", "this", "node" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/bitseq/sequence.go#L121-L131
22,693
docker/libnetwork
bitseq/sequence.go
equal
func (s *sequence) equal(o *sequence) bool { this := s other := o for this != nil { if other == nil { return false } if this.block != other.block || this.count != other.count { return false } this = this.next other = other.next } // Check if other is longer than this if other != nil { return false } return true }
go
func (s *sequence) equal(o *sequence) bool { this := s other := o for this != nil { if other == nil { return false } if this.block != other.block || this.count != other.count { return false } this = this.next other = other.next } // Check if other is longer than this if other != nil { return false } return true }
[ "func", "(", "s", "*", "sequence", ")", "equal", "(", "o", "*", "sequence", ")", "bool", "{", "this", ":=", "s", "\n", "other", ":=", "o", "\n", "for", "this", "!=", "nil", "{", "if", "other", "==", "nil", "{", "return", "false", "\n", "}", "\n", "if", "this", ".", "block", "!=", "other", ".", "block", "||", "this", ".", "count", "!=", "other", ".", "count", "{", "return", "false", "\n", "}", "\n", "this", "=", "this", ".", "next", "\n", "other", "=", "other", ".", "next", "\n", "}", "\n", "// Check if other is longer than this", "if", "other", "!=", "nil", "{", "return", "false", "\n", "}", "\n", "return", "true", "\n", "}" ]
// Equal checks if this sequence is equal to the passed one
[ "Equal", "checks", "if", "this", "sequence", "is", "equal", "to", "the", "passed", "one" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/bitseq/sequence.go#L134-L152
22,694
docker/libnetwork
bitseq/sequence.go
toByteArray
func (s *sequence) toByteArray() ([]byte, error) { var bb []byte p := s for p != nil { b := make([]byte, 12) binary.BigEndian.PutUint32(b[0:], p.block) binary.BigEndian.PutUint64(b[4:], p.count) bb = append(bb, b...) p = p.next } return bb, nil }
go
func (s *sequence) toByteArray() ([]byte, error) { var bb []byte p := s for p != nil { b := make([]byte, 12) binary.BigEndian.PutUint32(b[0:], p.block) binary.BigEndian.PutUint64(b[4:], p.count) bb = append(bb, b...) p = p.next } return bb, nil }
[ "func", "(", "s", "*", "sequence", ")", "toByteArray", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "var", "bb", "[", "]", "byte", "\n\n", "p", ":=", "s", "\n", "for", "p", "!=", "nil", "{", "b", ":=", "make", "(", "[", "]", "byte", ",", "12", ")", "\n", "binary", ".", "BigEndian", ".", "PutUint32", "(", "b", "[", "0", ":", "]", ",", "p", ".", "block", ")", "\n", "binary", ".", "BigEndian", ".", "PutUint64", "(", "b", "[", "4", ":", "]", ",", "p", ".", "count", ")", "\n", "bb", "=", "append", "(", "bb", ",", "b", "...", ")", "\n", "p", "=", "p", ".", "next", "\n", "}", "\n\n", "return", "bb", ",", "nil", "\n", "}" ]
// ToByteArray converts the sequence into a byte array
[ "ToByteArray", "converts", "the", "sequence", "into", "a", "byte", "array" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/bitseq/sequence.go#L155-L168
22,695
docker/libnetwork
bitseq/sequence.go
fromByteArray
func (s *sequence) fromByteArray(data []byte) error { l := len(data) if l%12 != 0 { return fmt.Errorf("cannot deserialize byte sequence of length %d (%v)", l, data) } p := s i := 0 for { p.block = binary.BigEndian.Uint32(data[i : i+4]) p.count = binary.BigEndian.Uint64(data[i+4 : i+12]) i += 12 if i == l { break } p.next = &sequence{} p = p.next } return nil }
go
func (s *sequence) fromByteArray(data []byte) error { l := len(data) if l%12 != 0 { return fmt.Errorf("cannot deserialize byte sequence of length %d (%v)", l, data) } p := s i := 0 for { p.block = binary.BigEndian.Uint32(data[i : i+4]) p.count = binary.BigEndian.Uint64(data[i+4 : i+12]) i += 12 if i == l { break } p.next = &sequence{} p = p.next } return nil }
[ "func", "(", "s", "*", "sequence", ")", "fromByteArray", "(", "data", "[", "]", "byte", ")", "error", "{", "l", ":=", "len", "(", "data", ")", "\n", "if", "l", "%", "12", "!=", "0", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "l", ",", "data", ")", "\n", "}", "\n\n", "p", ":=", "s", "\n", "i", ":=", "0", "\n", "for", "{", "p", ".", "block", "=", "binary", ".", "BigEndian", ".", "Uint32", "(", "data", "[", "i", ":", "i", "+", "4", "]", ")", "\n", "p", ".", "count", "=", "binary", ".", "BigEndian", ".", "Uint64", "(", "data", "[", "i", "+", "4", ":", "i", "+", "12", "]", ")", "\n", "i", "+=", "12", "\n", "if", "i", "==", "l", "{", "break", "\n", "}", "\n", "p", ".", "next", "=", "&", "sequence", "{", "}", "\n", "p", "=", "p", ".", "next", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// fromByteArray construct the sequence from the byte array
[ "fromByteArray", "construct", "the", "sequence", "from", "the", "byte", "array" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/bitseq/sequence.go#L171-L191
22,696
docker/libnetwork
bitseq/sequence.go
SetAnyInRange
func (h *Handle) SetAnyInRange(start, end uint64, serial bool) (uint64, error) { if end < start || end >= h.bits { return invalidPos, fmt.Errorf("invalid bit range [%d, %d]", start, end) } if h.Unselected() == 0 { return invalidPos, ErrNoBitAvailable } return h.set(0, start, end, true, false, serial) }
go
func (h *Handle) SetAnyInRange(start, end uint64, serial bool) (uint64, error) { if end < start || end >= h.bits { return invalidPos, fmt.Errorf("invalid bit range [%d, %d]", start, end) } if h.Unselected() == 0 { return invalidPos, ErrNoBitAvailable } return h.set(0, start, end, true, false, serial) }
[ "func", "(", "h", "*", "Handle", ")", "SetAnyInRange", "(", "start", ",", "end", "uint64", ",", "serial", "bool", ")", "(", "uint64", ",", "error", ")", "{", "if", "end", "<", "start", "||", "end", ">=", "h", ".", "bits", "{", "return", "invalidPos", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "start", ",", "end", ")", "\n", "}", "\n", "if", "h", ".", "Unselected", "(", ")", "==", "0", "{", "return", "invalidPos", ",", "ErrNoBitAvailable", "\n", "}", "\n", "return", "h", ".", "set", "(", "0", ",", "start", ",", "end", ",", "true", ",", "false", ",", "serial", ")", "\n", "}" ]
// SetAnyInRange atomically sets the first unset bit in the specified range in the sequence and returns the corresponding ordinal
[ "SetAnyInRange", "atomically", "sets", "the", "first", "unset", "bit", "in", "the", "specified", "range", "in", "the", "sequence", "and", "returns", "the", "corresponding", "ordinal" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/bitseq/sequence.go#L208-L216
22,697
docker/libnetwork
bitseq/sequence.go
SetAny
func (h *Handle) SetAny(serial bool) (uint64, error) { if h.Unselected() == 0 { return invalidPos, ErrNoBitAvailable } return h.set(0, 0, h.bits-1, true, false, serial) }
go
func (h *Handle) SetAny(serial bool) (uint64, error) { if h.Unselected() == 0 { return invalidPos, ErrNoBitAvailable } return h.set(0, 0, h.bits-1, true, false, serial) }
[ "func", "(", "h", "*", "Handle", ")", "SetAny", "(", "serial", "bool", ")", "(", "uint64", ",", "error", ")", "{", "if", "h", ".", "Unselected", "(", ")", "==", "0", "{", "return", "invalidPos", ",", "ErrNoBitAvailable", "\n", "}", "\n", "return", "h", ".", "set", "(", "0", ",", "0", ",", "h", ".", "bits", "-", "1", ",", "true", ",", "false", ",", "serial", ")", "\n", "}" ]
// SetAny atomically sets the first unset bit in the sequence and returns the corresponding ordinal
[ "SetAny", "atomically", "sets", "the", "first", "unset", "bit", "in", "the", "sequence", "and", "returns", "the", "corresponding", "ordinal" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/bitseq/sequence.go#L219-L224
22,698
docker/libnetwork
bitseq/sequence.go
Set
func (h *Handle) Set(ordinal uint64) error { if err := h.validateOrdinal(ordinal); err != nil { return err } _, err := h.set(ordinal, 0, 0, false, false, false) return err }
go
func (h *Handle) Set(ordinal uint64) error { if err := h.validateOrdinal(ordinal); err != nil { return err } _, err := h.set(ordinal, 0, 0, false, false, false) return err }
[ "func", "(", "h", "*", "Handle", ")", "Set", "(", "ordinal", "uint64", ")", "error", "{", "if", "err", ":=", "h", ".", "validateOrdinal", "(", "ordinal", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "_", ",", "err", ":=", "h", ".", "set", "(", "ordinal", ",", "0", ",", "0", ",", "false", ",", "false", ",", "false", ")", "\n", "return", "err", "\n", "}" ]
// Set atomically sets the corresponding bit in the sequence
[ "Set", "atomically", "sets", "the", "corresponding", "bit", "in", "the", "sequence" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/bitseq/sequence.go#L227-L233
22,699
docker/libnetwork
bitseq/sequence.go
Unset
func (h *Handle) Unset(ordinal uint64) error { if err := h.validateOrdinal(ordinal); err != nil { return err } _, err := h.set(ordinal, 0, 0, false, true, false) return err }
go
func (h *Handle) Unset(ordinal uint64) error { if err := h.validateOrdinal(ordinal); err != nil { return err } _, err := h.set(ordinal, 0, 0, false, true, false) return err }
[ "func", "(", "h", "*", "Handle", ")", "Unset", "(", "ordinal", "uint64", ")", "error", "{", "if", "err", ":=", "h", ".", "validateOrdinal", "(", "ordinal", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "_", ",", "err", ":=", "h", ".", "set", "(", "ordinal", ",", "0", ",", "0", ",", "false", ",", "true", ",", "false", ")", "\n", "return", "err", "\n", "}" ]
// Unset atomically unsets the corresponding bit in the sequence
[ "Unset", "atomically", "unsets", "the", "corresponding", "bit", "in", "the", "sequence" ]
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/bitseq/sequence.go#L236-L242