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
11,800
newrelic/sidecar
sidecarhttp/http_api.go
oneServiceHandler
func (s *SidecarApi) oneServiceHandler(response http.ResponseWriter, req *http.Request, params map[string]string) { defer req.Body.Close() response.Header().Set("Access-Control-Allow-Origin", "*") response.Header().Set("Access-Control-Allow-Methods", "GET") response.Header().Set("Content-Type", "application/json")...
go
func (s *SidecarApi) oneServiceHandler(response http.ResponseWriter, req *http.Request, params map[string]string) { defer req.Body.Close() response.Header().Set("Access-Control-Allow-Origin", "*") response.Header().Set("Access-Control-Allow-Methods", "GET") response.Header().Set("Content-Type", "application/json")...
[ "func", "(", "s", "*", "SidecarApi", ")", "oneServiceHandler", "(", "response", "http", ".", "ResponseWriter", ",", "req", "*", "http", ".", "Request", ",", "params", "map", "[", "string", "]", "string", ")", "{", "defer", "req", ".", "Body", ".", "Clo...
// oneServiceHandler takes the name of a single service and returns results for just // that service.
[ "oneServiceHandler", "takes", "the", "name", "of", "a", "single", "service", "and", "returns", "results", "for", "just", "that", "service", "." ]
8327834c20bca8a155ccac8bc42ab2f42ca925a6
https://github.com/newrelic/sidecar/blob/8327834c20bca8a155ccac8bc42ab2f42ca925a6/sidecarhttp/http_api.go#L129-L190
11,801
newrelic/sidecar
sidecarhttp/http_api.go
servicesHandler
func (s *SidecarApi) servicesHandler(response http.ResponseWriter, req *http.Request, params map[string]string) { defer req.Body.Close() response.Header().Set("Access-Control-Allow-Origin", "*") response.Header().Set("Access-Control-Allow-Methods", "GET") // We only support JSON if params["extension"] != "json" ...
go
func (s *SidecarApi) servicesHandler(response http.ResponseWriter, req *http.Request, params map[string]string) { defer req.Body.Close() response.Header().Set("Access-Control-Allow-Origin", "*") response.Header().Set("Access-Control-Allow-Methods", "GET") // We only support JSON if params["extension"] != "json" ...
[ "func", "(", "s", "*", "SidecarApi", ")", "servicesHandler", "(", "response", "http", ".", "ResponseWriter", ",", "req", "*", "http", ".", "Request", ",", "params", "map", "[", "string", "]", "string", ")", "{", "defer", "req", ".", "Body", ".", "Close...
// serviceHandler returns the results for all the services we know about
[ "serviceHandler", "returns", "the", "results", "for", "all", "the", "services", "we", "know", "about" ]
8327834c20bca8a155ccac8bc42ab2f42ca925a6
https://github.com/newrelic/sidecar/blob/8327834c20bca8a155ccac8bc42ab2f42ca925a6/sidecarhttp/http_api.go#L193-L256
11,802
newrelic/sidecar
sidecarhttp/http_api.go
stateHandler
func (s *SidecarApi) stateHandler(response http.ResponseWriter, req *http.Request, params map[string]string) { defer req.Body.Close() s.state.RLock() defer s.state.RUnlock() if params["extension"] != "json" { sendJsonError(response, 404, "Not Found - Invalid content type extension") return } response.Heade...
go
func (s *SidecarApi) stateHandler(response http.ResponseWriter, req *http.Request, params map[string]string) { defer req.Body.Close() s.state.RLock() defer s.state.RUnlock() if params["extension"] != "json" { sendJsonError(response, 404, "Not Found - Invalid content type extension") return } response.Heade...
[ "func", "(", "s", "*", "SidecarApi", ")", "stateHandler", "(", "response", "http", ".", "ResponseWriter", ",", "req", "*", "http", ".", "Request", ",", "params", "map", "[", "string", "]", "string", ")", "{", "defer", "req", ".", "Body", ".", "Close", ...
// stateHandler simply dumps the JSON output of the whole state object. This is // useful for listeners or other clients that need a full state dump on startup.
[ "stateHandler", "simply", "dumps", "the", "JSON", "output", "of", "the", "whole", "state", "object", ".", "This", "is", "useful", "for", "listeners", "or", "other", "clients", "that", "need", "a", "full", "state", "dump", "on", "startup", "." ]
8327834c20bca8a155ccac8bc42ab2f42ca925a6
https://github.com/newrelic/sidecar/blob/8327834c20bca8a155ccac8bc42ab2f42ca925a6/sidecarhttp/http_api.go#L260-L276
11,803
newrelic/sidecar
sidecarhttp/http_api.go
sendJsonError
func sendJsonError(response http.ResponseWriter, status int, message string) { output := map[string]string{ "status": "error", "message": message, } jsonBytes, err := json.Marshal(output) if err != nil { log.Errorf("Error encoding json error response: %s", err.Error()) response.WriteHeader(500) respons...
go
func sendJsonError(response http.ResponseWriter, status int, message string) { output := map[string]string{ "status": "error", "message": message, } jsonBytes, err := json.Marshal(output) if err != nil { log.Errorf("Error encoding json error response: %s", err.Error()) response.WriteHeader(500) respons...
[ "func", "sendJsonError", "(", "response", "http", ".", "ResponseWriter", ",", "status", "int", ",", "message", "string", ")", "{", "output", ":=", "map", "[", "string", "]", "string", "{", "\"", "\"", ":", "\"", "\"", ",", "\"", "\"", ":", "message", ...
// Send back a JSON encoded error and message
[ "Send", "back", "a", "JSON", "encoded", "error", "and", "message" ]
8327834c20bca8a155ccac8bc42ab2f42ca925a6
https://github.com/newrelic/sidecar/blob/8327834c20bca8a155ccac8bc42ab2f42ca925a6/sidecarhttp/http_api.go#L279-L297
11,804
newrelic/sidecar
healthy/service_bridge.go
defaultCheckForService
func (m *Monitor) defaultCheckForService(svc *service.Service) *Check { port := findFirstTCPPort(svc) if port == nil { return &Check{ID: svc.ID, Command: &AlwaysSuccessfulCmd{}} } // Use the const default unless we've been provided something else defaultCheckEndpoint := DEFAULT_STATUS_ENDPOINT if len(m.Default...
go
func (m *Monitor) defaultCheckForService(svc *service.Service) *Check { port := findFirstTCPPort(svc) if port == nil { return &Check{ID: svc.ID, Command: &AlwaysSuccessfulCmd{}} } // Use the const default unless we've been provided something else defaultCheckEndpoint := DEFAULT_STATUS_ENDPOINT if len(m.Default...
[ "func", "(", "m", "*", "Monitor", ")", "defaultCheckForService", "(", "svc", "*", "service", ".", "Service", ")", "*", "Check", "{", "port", ":=", "findFirstTCPPort", "(", "svc", ")", "\n", "if", "port", "==", "nil", "{", "return", "&", "Check", "{", ...
// Configure a default check for a service. The default is to return an HTTP // check on the first TCP port on the endpoint set in DEFAULT_STATUS_ENDPOINT.
[ "Configure", "a", "default", "check", "for", "a", "service", ".", "The", "default", "is", "to", "return", "an", "HTTP", "check", "on", "the", "first", "TCP", "port", "on", "the", "endpoint", "set", "in", "DEFAULT_STATUS_ENDPOINT", "." ]
8327834c20bca8a155ccac8bc42ab2f42ca925a6
https://github.com/newrelic/sidecar/blob/8327834c20bca8a155ccac8bc42ab2f42ca925a6/healthy/service_bridge.go#L50-L70
11,805
newrelic/sidecar
healthy/service_bridge.go
fetchCheckForService
func (m *Monitor) fetchCheckForService(svc *service.Service, disco discovery.Discoverer) *Check { check := &Check{} check.Type, check.Args = disco.HealthCheck(svc) if check.Type == "" { log.Warnf("Got empty check type for service %s (id: %s) with args: %s!", svc.Name, svc.ID, check.Args) return nil } // Setu...
go
func (m *Monitor) fetchCheckForService(svc *service.Service, disco discovery.Discoverer) *Check { check := &Check{} check.Type, check.Args = disco.HealthCheck(svc) if check.Type == "" { log.Warnf("Got empty check type for service %s (id: %s) with args: %s!", svc.Name, svc.ID, check.Args) return nil } // Setu...
[ "func", "(", "m", "*", "Monitor", ")", "fetchCheckForService", "(", "svc", "*", "service", ".", "Service", ",", "disco", "discovery", ".", "Discoverer", ")", "*", "Check", "{", "check", ":=", "&", "Check", "{", "}", "\n", "check", ".", "Type", ",", "...
// Talks to a Discoverer and returns the configured check
[ "Talks", "to", "a", "Discoverer", "and", "returns", "the", "configured", "check" ]
8327834c20bca8a155ccac8bc42ab2f42ca925a6
https://github.com/newrelic/sidecar/blob/8327834c20bca8a155ccac8bc42ab2f42ca925a6/healthy/service_bridge.go#L86-L101
11,806
newrelic/sidecar
healthy/service_bridge.go
templateCheckArgs
func (m *Monitor) templateCheckArgs(check *Check, svc *service.Service) string { funcMap := template.FuncMap{ "tcp": func(p int64) int64 { return svc.PortForServicePort(p, "tcp") }, "udp": func(p int64) int64 { return svc.PortForServicePort(p, "udp") }, "host": func() string { return m.DefaultCh...
go
func (m *Monitor) templateCheckArgs(check *Check, svc *service.Service) string { funcMap := template.FuncMap{ "tcp": func(p int64) int64 { return svc.PortForServicePort(p, "tcp") }, "udp": func(p int64) int64 { return svc.PortForServicePort(p, "udp") }, "host": func() string { return m.DefaultCh...
[ "func", "(", "m", "*", "Monitor", ")", "templateCheckArgs", "(", "check", "*", "Check", ",", "svc", "*", "service", ".", "Service", ")", "string", "{", "funcMap", ":=", "template", ".", "FuncMap", "{", "\"", "\"", ":", "func", "(", "p", "int64", ")",...
// Use templating to substitute in some info about the service. Important because // we won't know the actual Port that the container will bind to, for example.
[ "Use", "templating", "to", "substitute", "in", "some", "info", "about", "the", "service", ".", "Important", "because", "we", "won", "t", "know", "the", "actual", "Port", "that", "the", "container", "will", "bind", "to", "for", "example", "." ]
8327834c20bca8a155ccac8bc42ab2f42ca925a6
https://github.com/newrelic/sidecar/blob/8327834c20bca8a155ccac8bc42ab2f42ca925a6/healthy/service_bridge.go#L105-L123
11,807
newrelic/sidecar
healthy/service_bridge.go
CheckForService
func (m *Monitor) CheckForService(svc *service.Service, disco discovery.Discoverer) *Check { check := m.fetchCheckForService(svc, disco) if check == nil { // We got nothing log.Warnf("Using default check for service %s (id: %s).", svc.Name, svc.ID) check = m.defaultCheckForService(svc) } check.Args = m.templat...
go
func (m *Monitor) CheckForService(svc *service.Service, disco discovery.Discoverer) *Check { check := m.fetchCheckForService(svc, disco) if check == nil { // We got nothing log.Warnf("Using default check for service %s (id: %s).", svc.Name, svc.ID) check = m.defaultCheckForService(svc) } check.Args = m.templat...
[ "func", "(", "m", "*", "Monitor", ")", "CheckForService", "(", "svc", "*", "service", ".", "Service", ",", "disco", "discovery", ".", "Discoverer", ")", "*", "Check", "{", "check", ":=", "m", ".", "fetchCheckForService", "(", "svc", ",", "disco", ")", ...
// CheckForService returns a Check that has been properly configured for this // particular service.
[ "CheckForService", "returns", "a", "Check", "that", "has", "been", "properly", "configured", "for", "this", "particular", "service", "." ]
8327834c20bca8a155ccac8bc42ab2f42ca925a6
https://github.com/newrelic/sidecar/blob/8327834c20bca8a155ccac8bc42ab2f42ca925a6/healthy/service_bridge.go#L127-L137
11,808
newrelic/sidecar
healthy/service_bridge.go
Watch
func (m *Monitor) Watch(disco discovery.Discoverer, looper director.Looper) { m.DiscoveryFn = disco.Services // Store this so we can use it from Services() looper.Loop(func() error { services := disco.Services() // Add checks when new services are found for _, svc := range services { if m.Checks[svc.ID] ==...
go
func (m *Monitor) Watch(disco discovery.Discoverer, looper director.Looper) { m.DiscoveryFn = disco.Services // Store this so we can use it from Services() looper.Loop(func() error { services := disco.Services() // Add checks when new services are found for _, svc := range services { if m.Checks[svc.ID] ==...
[ "func", "(", "m", "*", "Monitor", ")", "Watch", "(", "disco", "discovery", ".", "Discoverer", ",", "looper", "director", ".", "Looper", ")", "{", "m", ".", "DiscoveryFn", "=", "disco", ".", "Services", "// Store this so we can use it from Services()", "\n\n", ...
// Watch loops over a list of services and adds checks for services we don't already // know about. It then removes any checks for services which have gone away. All // services are expected to be local to this node.
[ "Watch", "loops", "over", "a", "list", "of", "services", "and", "adds", "checks", "for", "services", "we", "don", "t", "already", "know", "about", ".", "It", "then", "removes", "any", "checks", "for", "services", "which", "have", "gone", "away", ".", "Al...
8327834c20bca8a155ccac8bc42ab2f42ca925a6
https://github.com/newrelic/sidecar/blob/8327834c20bca8a155ccac8bc42ab2f42ca925a6/healthy/service_bridge.go#L142-L183
11,809
newrelic/sidecar
discovery/static_discovery.go
Services
func (d *StaticDiscovery) Services() []service.Service { var services []service.Service for _, target := range d.Targets { target.Service.Updated = time.Now().UTC() services = append(services, target.Service) } return services }
go
func (d *StaticDiscovery) Services() []service.Service { var services []service.Service for _, target := range d.Targets { target.Service.Updated = time.Now().UTC() services = append(services, target.Service) } return services }
[ "func", "(", "d", "*", "StaticDiscovery", ")", "Services", "(", ")", "[", "]", "service", ".", "Service", "{", "var", "services", "[", "]", "service", ".", "Service", "\n", "for", "_", ",", "target", ":=", "range", "d", ".", "Targets", "{", "target",...
// Returns the list of services derived from the targets that were parsed // out of the config file.
[ "Returns", "the", "list", "of", "services", "derived", "from", "the", "targets", "that", "were", "parsed", "out", "of", "the", "config", "file", "." ]
8327834c20bca8a155ccac8bc42ab2f42ca925a6
https://github.com/newrelic/sidecar/blob/8327834c20bca8a155ccac8bc42ab2f42ca925a6/discovery/static_discovery.go#L62-L69
11,810
newrelic/sidecar
discovery/static_discovery.go
Listeners
func (d *StaticDiscovery) Listeners() []ChangeListener { var listeners []ChangeListener for _, target := range d.Targets { if target.ListenPort > 0 { listener := ChangeListener{ Name: target.Service.ListenerName(), Url: fmt.Sprintf("http://%s:%d/sidecar/update", d.Hostname, target.ListenPort), } l...
go
func (d *StaticDiscovery) Listeners() []ChangeListener { var listeners []ChangeListener for _, target := range d.Targets { if target.ListenPort > 0 { listener := ChangeListener{ Name: target.Service.ListenerName(), Url: fmt.Sprintf("http://%s:%d/sidecar/update", d.Hostname, target.ListenPort), } l...
[ "func", "(", "d", "*", "StaticDiscovery", ")", "Listeners", "(", ")", "[", "]", "ChangeListener", "{", "var", "listeners", "[", "]", "ChangeListener", "\n", "for", "_", ",", "target", ":=", "range", "d", ".", "Targets", "{", "if", "target", ".", "Liste...
// Listeners returns the list of services configured to be ChangeEvent listeners
[ "Listeners", "returns", "the", "list", "of", "services", "configured", "to", "be", "ChangeEvent", "listeners" ]
8327834c20bca8a155ccac8bc42ab2f42ca925a6
https://github.com/newrelic/sidecar/blob/8327834c20bca8a155ccac8bc42ab2f42ca925a6/discovery/static_discovery.go#L72-L84
11,811
newrelic/sidecar
discovery/static_discovery.go
Run
func (d *StaticDiscovery) Run(looper director.Looper) { var err error d.Targets, err = d.ParseConfig(d.ConfigFile) if err != nil { log.Errorf("StaticDiscovery cannot parse: %s", err.Error()) looper.Done(nil) } }
go
func (d *StaticDiscovery) Run(looper director.Looper) { var err error d.Targets, err = d.ParseConfig(d.ConfigFile) if err != nil { log.Errorf("StaticDiscovery cannot parse: %s", err.Error()) looper.Done(nil) } }
[ "func", "(", "d", "*", "StaticDiscovery", ")", "Run", "(", "looper", "director", ".", "Looper", ")", "{", "var", "err", "error", "\n\n", "d", ".", "Targets", ",", "err", "=", "d", ".", "ParseConfig", "(", "d", ".", "ConfigFile", ")", "\n", "if", "e...
// Causes the configuration to be parsed and loaded. There is no background // processing needed on an ongoing basis.
[ "Causes", "the", "configuration", "to", "be", "parsed", "and", "loaded", ".", "There", "is", "no", "background", "processing", "needed", "on", "an", "ongoing", "basis", "." ]
8327834c20bca8a155ccac8bc42ab2f42ca925a6
https://github.com/newrelic/sidecar/blob/8327834c20bca8a155ccac8bc42ab2f42ca925a6/discovery/static_discovery.go#L88-L96
11,812
newrelic/sidecar
discovery/static_discovery.go
ParseConfig
func (d *StaticDiscovery) ParseConfig(filename string) ([]*Target, error) { file, err := ioutil.ReadFile(filename) if err != nil { log.Errorf("Unable to read announcements file: '%s!'", err.Error()) return nil, err } var targets []*Target err = json.Unmarshal(file, &targets) if err != nil { return nil, fmt...
go
func (d *StaticDiscovery) ParseConfig(filename string) ([]*Target, error) { file, err := ioutil.ReadFile(filename) if err != nil { log.Errorf("Unable to read announcements file: '%s!'", err.Error()) return nil, err } var targets []*Target err = json.Unmarshal(file, &targets) if err != nil { return nil, fmt...
[ "func", "(", "d", "*", "StaticDiscovery", ")", "ParseConfig", "(", "filename", "string", ")", "(", "[", "]", "*", "Target", ",", "error", ")", "{", "file", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "filename", ")", "\n", "if", "err", "!=", ...
// Parses a JSON config file containing an array of Targets. These are // then augmented with a random hex ID and stamped with the current // UTC time as the creation time. The same hex ID is applied to the Check // and the Service to make sure that they are matched by the healthy // package later on.
[ "Parses", "a", "JSON", "config", "file", "containing", "an", "array", "of", "Targets", ".", "These", "are", "then", "augmented", "with", "a", "random", "hex", "ID", "and", "stamped", "with", "the", "current", "UTC", "time", "as", "the", "creation", "time",...
8327834c20bca8a155ccac8bc42ab2f42ca925a6
https://github.com/newrelic/sidecar/blob/8327834c20bca8a155ccac8bc42ab2f42ca925a6/discovery/static_discovery.go#L103-L145
11,813
newrelic/sidecar
discovery/static_discovery.go
RandomHex
func RandomHex(count int) ([]byte, error) { raw := make([]byte, count) _, err := rand.Read(raw) if err != nil { log.Errorf("RandomBytes(): Error %s", err.Error()) return nil, err } encoded := make([]byte, count*2) hex.Encode(encoded, raw) return encoded, nil }
go
func RandomHex(count int) ([]byte, error) { raw := make([]byte, count) _, err := rand.Read(raw) if err != nil { log.Errorf("RandomBytes(): Error %s", err.Error()) return nil, err } encoded := make([]byte, count*2) hex.Encode(encoded, raw) return encoded, nil }
[ "func", "RandomHex", "(", "count", "int", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "raw", ":=", "make", "(", "[", "]", "byte", ",", "count", ")", "\n", "_", ",", "err", ":=", "rand", ".", "Read", "(", "raw", ")", "\n", "if", "err",...
// Return a defined number of random bytes as a slice
[ "Return", "a", "defined", "number", "of", "random", "bytes", "as", "a", "slice" ]
8327834c20bca8a155ccac8bc42ab2f42ca925a6
https://github.com/newrelic/sidecar/blob/8327834c20bca8a155ccac8bc42ab2f42ca925a6/discovery/static_discovery.go#L148-L159
11,814
newrelic/sidecar
sidecarhttp/envoy_api.go
optionsHandler
func (s *EnvoyApi) optionsHandler(response http.ResponseWriter, req *http.Request) { response.Header().Set("Access-Control-Allow-Origin", "*") response.Header().Set("Access-Control-Allow-Methods", "GET") return }
go
func (s *EnvoyApi) optionsHandler(response http.ResponseWriter, req *http.Request) { response.Header().Set("Access-Control-Allow-Origin", "*") response.Header().Set("Access-Control-Allow-Methods", "GET") return }
[ "func", "(", "s", "*", "EnvoyApi", ")", "optionsHandler", "(", "response", "http", ".", "ResponseWriter", ",", "req", "*", "http", ".", "Request", ")", "{", "response", ".", "Header", "(", ")", ".", "Set", "(", "\"", "\"", ",", "\"", "\"", ")", "\n...
// optionsHandler sends CORS headers
[ "optionsHandler", "sends", "CORS", "headers" ]
8327834c20bca8a155ccac8bc42ab2f42ca925a6
https://github.com/newrelic/sidecar/blob/8327834c20bca8a155ccac8bc42ab2f42ca925a6/sidecarhttp/envoy_api.go#L108-L112
11,815
newrelic/sidecar
sidecarhttp/envoy_api.go
registrationHandler
func (s *EnvoyApi) registrationHandler(response http.ResponseWriter, req *http.Request, params map[string]string) { defer req.Body.Close() response.Header().Set("Content-Type", "application/json") name, ok := params["service"] if !ok { log.Debug("No service name provided to Envoy registrationHandler") sendJso...
go
func (s *EnvoyApi) registrationHandler(response http.ResponseWriter, req *http.Request, params map[string]string) { defer req.Body.Close() response.Header().Set("Content-Type", "application/json") name, ok := params["service"] if !ok { log.Debug("No service name provided to Envoy registrationHandler") sendJso...
[ "func", "(", "s", "*", "EnvoyApi", ")", "registrationHandler", "(", "response", "http", ".", "ResponseWriter", ",", "req", "*", "http", ".", "Request", ",", "params", "map", "[", "string", "]", "string", ")", "{", "defer", "req", ".", "Body", ".", "Clo...
// registrationHandler takes the name of a single service and returns results for just // that service. It implements the Envoy SDS API V1.
[ "registrationHandler", "takes", "the", "name", "of", "a", "single", "service", "and", "returns", "results", "for", "just", "that", "service", ".", "It", "implements", "the", "Envoy", "SDS", "API", "V1", "." ]
8327834c20bca8a155ccac8bc42ab2f42ca925a6
https://github.com/newrelic/sidecar/blob/8327834c20bca8a155ccac8bc42ab2f42ca925a6/sidecarhttp/envoy_api.go#L122-L176
11,816
newrelic/sidecar
sidecarhttp/envoy_api.go
clustersHandler
func (s *EnvoyApi) clustersHandler(response http.ResponseWriter, req *http.Request, params map[string]string) { defer req.Body.Close() response.Header().Set("Content-Type", "application/json") clusters := s.EnvoyClustersFromState() log.Debugf("Reporting Envoy cluster information for cluster '%s' and node '%s'", ...
go
func (s *EnvoyApi) clustersHandler(response http.ResponseWriter, req *http.Request, params map[string]string) { defer req.Body.Close() response.Header().Set("Content-Type", "application/json") clusters := s.EnvoyClustersFromState() log.Debugf("Reporting Envoy cluster information for cluster '%s' and node '%s'", ...
[ "func", "(", "s", "*", "EnvoyApi", ")", "clustersHandler", "(", "response", "http", ".", "ResponseWriter", ",", "req", "*", "http", ".", "Request", ",", "params", "map", "[", "string", "]", "string", ")", "{", "defer", "req", ".", "Body", ".", "Close",...
// clustersHandler returns cluster information for all Sidecar services. It // implements the Envoy CDS API V1.
[ "clustersHandler", "returns", "cluster", "information", "for", "all", "Sidecar", "services", ".", "It", "implements", "the", "Envoy", "CDS", "API", "V1", "." ]
8327834c20bca8a155ccac8bc42ab2f42ca925a6
https://github.com/newrelic/sidecar/blob/8327834c20bca8a155ccac8bc42ab2f42ca925a6/sidecarhttp/envoy_api.go#L184-L205
11,817
newrelic/sidecar
sidecarhttp/envoy_api.go
listenersHandler
func (s *EnvoyApi) listenersHandler(response http.ResponseWriter, req *http.Request, params map[string]string) { defer req.Body.Close() response.Header().Set("Content-Type", "application/json") log.Debugf("Reporting Envoy cluster information for cluster '%s' and node '%s'", params["service_cluster"], params["ser...
go
func (s *EnvoyApi) listenersHandler(response http.ResponseWriter, req *http.Request, params map[string]string) { defer req.Body.Close() response.Header().Set("Content-Type", "application/json") log.Debugf("Reporting Envoy cluster information for cluster '%s' and node '%s'", params["service_cluster"], params["ser...
[ "func", "(", "s", "*", "EnvoyApi", ")", "listenersHandler", "(", "response", "http", ".", "ResponseWriter", ",", "req", "*", "http", ".", "Request", ",", "params", "map", "[", "string", "]", "string", ")", "{", "defer", "req", ".", "Body", ".", "Close"...
// listenersHandler returns a list of listeners for all ServicePorts. It // implements the Envoy LDS API V1.
[ "listenersHandler", "returns", "a", "list", "of", "listeners", "for", "all", "ServicePorts", ".", "It", "implements", "the", "Envoy", "LDS", "API", "V1", "." ]
8327834c20bca8a155ccac8bc42ab2f42ca925a6
https://github.com/newrelic/sidecar/blob/8327834c20bca8a155ccac8bc42ab2f42ca925a6/sidecarhttp/envoy_api.go#L213-L233
11,818
newrelic/sidecar
sidecarhttp/envoy_api.go
lookupHost
func lookupHost(hostname string) (string, error) { addrs, err := net.LookupHost(hostname) if err != nil { return "", err } return addrs[0], nil }
go
func lookupHost(hostname string) (string, error) { addrs, err := net.LookupHost(hostname) if err != nil { return "", err } return addrs[0], nil }
[ "func", "lookupHost", "(", "hostname", "string", ")", "(", "string", ",", "error", ")", "{", "addrs", ",", "err", ":=", "net", ".", "LookupHost", "(", "hostname", ")", "\n\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "...
// lookupHost does a vv slow lookup of the DNS host for a service. Totally // not optimized for high throughput. You should only do this in development // scenarios.
[ "lookupHost", "does", "a", "vv", "slow", "lookup", "of", "the", "DNS", "host", "for", "a", "service", ".", "Totally", "not", "optimized", "for", "high", "throughput", ".", "You", "should", "only", "do", "this", "in", "development", "scenarios", "." ]
8327834c20bca8a155ccac8bc42ab2f42ca925a6
https://github.com/newrelic/sidecar/blob/8327834c20bca8a155ccac8bc42ab2f42ca925a6/sidecarhttp/envoy_api.go#L238-L245
11,819
newrelic/sidecar
sidecarhttp/envoy_api.go
EnvoyServiceFromService
func (s *EnvoyApi) EnvoyServiceFromService(svc *service.Service, svcPort int64) *EnvoyService { if len(svc.Ports) < 1 { return nil } for _, port := range svc.Ports { // No sense worrying about unexposed ports if port.ServicePort == svcPort { address := port.IP // NOT recommended... this is very slow. U...
go
func (s *EnvoyApi) EnvoyServiceFromService(svc *service.Service, svcPort int64) *EnvoyService { if len(svc.Ports) < 1 { return nil } for _, port := range svc.Ports { // No sense worrying about unexposed ports if port.ServicePort == svcPort { address := port.IP // NOT recommended... this is very slow. U...
[ "func", "(", "s", "*", "EnvoyApi", ")", "EnvoyServiceFromService", "(", "svc", "*", "service", ".", "Service", ",", "svcPort", "int64", ")", "*", "EnvoyService", "{", "if", "len", "(", "svc", ".", "Ports", ")", "<", "1", "{", "return", "nil", "\n", "...
// EnvoyServiceFromService converts a Sidecar service to an Envoy // API service for reporting to the proxy
[ "EnvoyServiceFromService", "converts", "a", "Sidecar", "service", "to", "an", "Envoy", "API", "service", "for", "reporting", "to", "the", "proxy" ]
8327834c20bca8a155ccac8bc42ab2f42ca925a6
https://github.com/newrelic/sidecar/blob/8327834c20bca8a155ccac8bc42ab2f42ca925a6/sidecarhttp/envoy_api.go#L249-L283
11,820
newrelic/sidecar
sidecarhttp/envoy_api.go
EnvoyClustersFromState
func (s *EnvoyApi) EnvoyClustersFromState() []*EnvoyCluster { clusters := make([]*EnvoyCluster, 0) s.state.RLock() defer s.state.RUnlock() svcs := s.state.ByService() for svcName, endpoints := range svcs { if len(endpoints) < 1 { continue } var svc *service.Service for _, endpoint := range endpoints ...
go
func (s *EnvoyApi) EnvoyClustersFromState() []*EnvoyCluster { clusters := make([]*EnvoyCluster, 0) s.state.RLock() defer s.state.RUnlock() svcs := s.state.ByService() for svcName, endpoints := range svcs { if len(endpoints) < 1 { continue } var svc *service.Service for _, endpoint := range endpoints ...
[ "func", "(", "s", "*", "EnvoyApi", ")", "EnvoyClustersFromState", "(", ")", "[", "]", "*", "EnvoyCluster", "{", "clusters", ":=", "make", "(", "[", "]", "*", "EnvoyCluster", ",", "0", ")", "\n\n", "s", ".", "state", ".", "RLock", "(", ")", "\n", "d...
// EnvoyClustersFromState genenerates a set of Envoy API cluster // definitions from Sidecar state
[ "EnvoyClustersFromState", "genenerates", "a", "set", "of", "Envoy", "API", "cluster", "definitions", "from", "Sidecar", "state" ]
8327834c20bca8a155ccac8bc42ab2f42ca925a6
https://github.com/newrelic/sidecar/blob/8327834c20bca8a155ccac8bc42ab2f42ca925a6/sidecarhttp/envoy_api.go#L287-L327
11,821
newrelic/sidecar
sidecarhttp/envoy_api.go
EnvoyListenersFromState
func (s *EnvoyApi) EnvoyListenersFromState() []*EnvoyListener { listeners := make([]*EnvoyListener, 0) s.state.RLock() defer s.state.RUnlock() svcs := s.state.ByService() // Loop over all the services by service name for _, endpoints := range svcs { if len(endpoints) < 1 { continue } var svc *service....
go
func (s *EnvoyApi) EnvoyListenersFromState() []*EnvoyListener { listeners := make([]*EnvoyListener, 0) s.state.RLock() defer s.state.RUnlock() svcs := s.state.ByService() // Loop over all the services by service name for _, endpoints := range svcs { if len(endpoints) < 1 { continue } var svc *service....
[ "func", "(", "s", "*", "EnvoyApi", ")", "EnvoyListenersFromState", "(", ")", "[", "]", "*", "EnvoyListener", "{", "listeners", ":=", "make", "(", "[", "]", "*", "EnvoyListener", ",", "0", ")", "\n\n", "s", ".", "state", ".", "RLock", "(", ")", "\n", ...
// EnvoyListenersFromState creates a set of Enovy API listener // definitions from all the ServicePorts in the Sidecar state.
[ "EnvoyListenersFromState", "creates", "a", "set", "of", "Enovy", "API", "listener", "definitions", "from", "all", "the", "ServicePorts", "in", "the", "Sidecar", "state", "." ]
8327834c20bca8a155ccac8bc42ab2f42ca925a6
https://github.com/newrelic/sidecar/blob/8327834c20bca8a155ccac8bc42ab2f42ca925a6/sidecarhttp/envoy_api.go#L393-L433
11,822
newrelic/sidecar
sidecarhttp/envoy_api.go
SvcName
func SvcName(name string, port int64) string { return fmt.Sprintf("%s%s%d", name, ServiceNameSeparator, port) }
go
func SvcName(name string, port int64) string { return fmt.Sprintf("%s%s%d", name, ServiceNameSeparator, port) }
[ "func", "SvcName", "(", "name", "string", ",", "port", "int64", ")", "string", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "name", ",", "ServiceNameSeparator", ",", "port", ")", "\n", "}" ]
// Format an Envoy service name from our service name and port
[ "Format", "an", "Envoy", "service", "name", "from", "our", "service", "name", "and", "port" ]
8327834c20bca8a155ccac8bc42ab2f42ca925a6
https://github.com/newrelic/sidecar/blob/8327834c20bca8a155ccac8bc42ab2f42ca925a6/sidecarhttp/envoy_api.go#L436-L438
11,823
newrelic/sidecar
sidecarhttp/envoy_api.go
SvcNameSplit
func SvcNameSplit(name string) (string, int64, error) { parts := strings.Split(name, ServiceNameSeparator) if len(parts) < 2 { return "", -1, fmt.Errorf("%s", "Unable to split service name and port!") } svcName := parts[0] svcPort, err := strconv.ParseInt(parts[1], 10, 64) if err != nil { return "", -1, fmt....
go
func SvcNameSplit(name string) (string, int64, error) { parts := strings.Split(name, ServiceNameSeparator) if len(parts) < 2 { return "", -1, fmt.Errorf("%s", "Unable to split service name and port!") } svcName := parts[0] svcPort, err := strconv.ParseInt(parts[1], 10, 64) if err != nil { return "", -1, fmt....
[ "func", "SvcNameSplit", "(", "name", "string", ")", "(", "string", ",", "int64", ",", "error", ")", "{", "parts", ":=", "strings", ".", "Split", "(", "name", ",", "ServiceNameSeparator", ")", "\n", "if", "len", "(", "parts", ")", "<", "2", "{", "retu...
// Split an Enovy service name into our service name and port
[ "Split", "an", "Enovy", "service", "name", "into", "our", "service", "name", "and", "port" ]
8327834c20bca8a155ccac8bc42ab2f42ca925a6
https://github.com/newrelic/sidecar/blob/8327834c20bca8a155ccac8bc42ab2f42ca925a6/sidecarhttp/envoy_api.go#L441-L454
11,824
newrelic/sidecar
sidecarhttp/envoy_api.go
HttpMux
func (s *EnvoyApi) HttpMux() http.Handler { router := mux.NewRouter() router.HandleFunc("/registration/{service}", wrap(s.registrationHandler)).Methods("GET") router.HandleFunc("/clusters/{service_cluster}/{service_node}", wrap(s.clustersHandler)).Methods("GET") router.HandleFunc("/clusters", wrap(s.clustersHandler...
go
func (s *EnvoyApi) HttpMux() http.Handler { router := mux.NewRouter() router.HandleFunc("/registration/{service}", wrap(s.registrationHandler)).Methods("GET") router.HandleFunc("/clusters/{service_cluster}/{service_node}", wrap(s.clustersHandler)).Methods("GET") router.HandleFunc("/clusters", wrap(s.clustersHandler...
[ "func", "(", "s", "*", "EnvoyApi", ")", "HttpMux", "(", ")", "http", ".", "Handler", "{", "router", ":=", "mux", ".", "NewRouter", "(", ")", "\n", "router", ".", "HandleFunc", "(", "\"", "\"", ",", "wrap", "(", "s", ".", "registrationHandler", ")", ...
// HttpMux returns a configured Gorilla mux to handle all the endpoints // for the Envoy API.
[ "HttpMux", "returns", "a", "configured", "Gorilla", "mux", "to", "handle", "all", "the", "endpoints", "for", "the", "Envoy", "API", "." ]
8327834c20bca8a155ccac8bc42ab2f42ca925a6
https://github.com/newrelic/sidecar/blob/8327834c20bca8a155ccac8bc42ab2f42ca925a6/sidecarhttp/envoy_api.go#L458-L468
11,825
newrelic/sidecar
healthy/healthy.go
NewCheck
func NewCheck(id string) *Check { check := Check{ ID: id, Count: 0, Type: "http", Command: &HttpGetCmd{}, MaxCount: 1, Status: UNKNOWN, } return &check }
go
func NewCheck(id string) *Check { check := Check{ ID: id, Count: 0, Type: "http", Command: &HttpGetCmd{}, MaxCount: 1, Status: UNKNOWN, } return &check }
[ "func", "NewCheck", "(", "id", "string", ")", "*", "Check", "{", "check", ":=", "Check", "{", "ID", ":", "id", ",", "Count", ":", "0", ",", "Type", ":", "\"", "\"", ",", "Command", ":", "&", "HttpGetCmd", "{", "}", ",", "MaxCount", ":", "1", ",...
// NewCheck returns a properly configured default Check
[ "NewCheck", "returns", "a", "properly", "configured", "default", "Check" ]
8327834c20bca8a155ccac8bc42ab2f42ca925a6
https://github.com/newrelic/sidecar/blob/8327834c20bca8a155ccac8bc42ab2f42ca925a6/healthy/healthy.go#L81-L91
11,826
newrelic/sidecar
healthy/healthy.go
UpdateStatus
func (check *Check) UpdateStatus(status int, err error) { if err != nil { log.Debugf("Error executing check, status UNKNOWN: (id %s)", check.ID) check.Status = UNKNOWN check.LastError = err } else { check.Status = status } if status == HEALTHY { check.Count = 0 return } check.Count = check.Count + 1...
go
func (check *Check) UpdateStatus(status int, err error) { if err != nil { log.Debugf("Error executing check, status UNKNOWN: (id %s)", check.ID) check.Status = UNKNOWN check.LastError = err } else { check.Status = status } if status == HEALTHY { check.Count = 0 return } check.Count = check.Count + 1...
[ "func", "(", "check", "*", "Check", ")", "UpdateStatus", "(", "status", "int", ",", "err", "error", ")", "{", "if", "err", "!=", "nil", "{", "log", ".", "Debugf", "(", "\"", "\"", ",", "check", ".", "ID", ")", "\n", "check", ".", "Status", "=", ...
// UpdateStatus take the status integer and error and applies them to the status // of the current Check.
[ "UpdateStatus", "take", "the", "status", "integer", "and", "error", "and", "applies", "them", "to", "the", "status", "of", "the", "current", "Check", "." ]
8327834c20bca8a155ccac8bc42ab2f42ca925a6
https://github.com/newrelic/sidecar/blob/8327834c20bca8a155ccac8bc42ab2f42ca925a6/healthy/healthy.go#L95-L114
11,827
newrelic/sidecar
healthy/healthy.go
NewMonitor
func NewMonitor(defaultCheckHost string, defaultCheckEndpoint string) *Monitor { monitor := Monitor{ Checks: make(map[string]*Check, 5), CheckInterval: HEALTH_INTERVAL, DefaultCheckHost: defaultCheckHost, DefaultCheckEndpoint: defaultCheckEndpoint, } return &monitor }
go
func NewMonitor(defaultCheckHost string, defaultCheckEndpoint string) *Monitor { monitor := Monitor{ Checks: make(map[string]*Check, 5), CheckInterval: HEALTH_INTERVAL, DefaultCheckHost: defaultCheckHost, DefaultCheckEndpoint: defaultCheckEndpoint, } return &monitor }
[ "func", "NewMonitor", "(", "defaultCheckHost", "string", ",", "defaultCheckEndpoint", "string", ")", "*", "Monitor", "{", "monitor", ":=", "Monitor", "{", "Checks", ":", "make", "(", "map", "[", "string", "]", "*", "Check", ",", "5", ")", ",", "CheckInterv...
// NewMonitor returns a properly configured default configuration of a Monitor.
[ "NewMonitor", "returns", "a", "properly", "configured", "default", "configuration", "of", "a", "Monitor", "." ]
8327834c20bca8a155ccac8bc42ab2f42ca925a6
https://github.com/newrelic/sidecar/blob/8327834c20bca8a155ccac8bc42ab2f42ca925a6/healthy/healthy.go#L130-L138
11,828
newrelic/sidecar
healthy/healthy.go
AddCheck
func (m *Monitor) AddCheck(check *Check) { m.Lock() defer m.Unlock() log.Printf("Adding health check: %s (ID: %s), Args: %s", check.Type, check.ID, check.Args) m.Checks[check.ID] = check }
go
func (m *Monitor) AddCheck(check *Check) { m.Lock() defer m.Unlock() log.Printf("Adding health check: %s (ID: %s), Args: %s", check.Type, check.ID, check.Args) m.Checks[check.ID] = check }
[ "func", "(", "m", "*", "Monitor", ")", "AddCheck", "(", "check", "*", "Check", ")", "{", "m", ".", "Lock", "(", ")", "\n", "defer", "m", ".", "Unlock", "(", ")", "\n", "log", ".", "Printf", "(", "\"", "\"", ",", "check", ".", "Type", ",", "ch...
// Add a Check to the list. Handles synchronization.
[ "Add", "a", "Check", "to", "the", "list", ".", "Handles", "synchronization", "." ]
8327834c20bca8a155ccac8bc42ab2f42ca925a6
https://github.com/newrelic/sidecar/blob/8327834c20bca8a155ccac8bc42ab2f42ca925a6/healthy/healthy.go#L141-L146
11,829
newrelic/sidecar
healthy/healthy.go
MarkService
func (m *Monitor) MarkService(svc *service.Service) { // We remove checks when encountering a Tombstone record. This // prevents us from storing up checks forever. The discovery // mechanism must create tombstones when services go away, so // this is the best signal we'll get that a check is no longer // needed. A...
go
func (m *Monitor) MarkService(svc *service.Service) { // We remove checks when encountering a Tombstone record. This // prevents us from storing up checks forever. The discovery // mechanism must create tombstones when services go away, so // this is the best signal we'll get that a check is no longer // needed. A...
[ "func", "(", "m", "*", "Monitor", ")", "MarkService", "(", "svc", "*", "service", ".", "Service", ")", "{", "// We remove checks when encountering a Tombstone record. This", "// prevents us from storing up checks forever. The discovery", "// mechanism must create tombstones when se...
// MarkService takes a service and mark its Status appropriately based on the // current check we have configured.
[ "MarkService", "takes", "a", "service", "and", "mark", "its", "Status", "appropriately", "based", "on", "the", "current", "check", "we", "have", "configured", "." ]
8327834c20bca8a155ccac8bc42ab2f42ca925a6
https://github.com/newrelic/sidecar/blob/8327834c20bca8a155ccac8bc42ab2f42ca925a6/healthy/healthy.go#L150-L163
11,830
newrelic/sidecar
healthy/healthy.go
Run
func (m *Monitor) Run(looper director.Looper) { looper.Loop(func() error { log.Debugf("Running checks") var wg sync.WaitGroup // Make immutable copy of m.Checks (checks are still mutable) m.RLock() checks := make(map[string]*Check, len(m.Checks)) for k, v := range m.Checks { checks[k] = v } m.RUnl...
go
func (m *Monitor) Run(looper director.Looper) { looper.Loop(func() error { log.Debugf("Running checks") var wg sync.WaitGroup // Make immutable copy of m.Checks (checks are still mutable) m.RLock() checks := make(map[string]*Check, len(m.Checks)) for k, v := range m.Checks { checks[k] = v } m.RUnl...
[ "func", "(", "m", "*", "Monitor", ")", "Run", "(", "looper", "director", ".", "Looper", ")", "{", "looper", ".", "Loop", "(", "func", "(", ")", "error", "{", "log", ".", "Debugf", "(", "\"", "\"", ")", "\n\n", "var", "wg", "sync", ".", "WaitGroup...
// Run runs the main monitoring loop. The looper controls the actual run behavior.
[ "Run", "runs", "the", "main", "monitoring", "loop", ".", "The", "looper", "controls", "the", "actual", "run", "behavior", "." ]
8327834c20bca8a155ccac8bc42ab2f42ca925a6
https://github.com/newrelic/sidecar/blob/8327834c20bca8a155ccac8bc42ab2f42ca925a6/healthy/healthy.go#L166-L213
11,831
newrelic/sidecar
discovery/service_namer.go
ServiceName
func (r *RegexpNamer) ServiceName(container *docker.APIContainers) string { if container == nil { log.Warn("ServiceName() called with nil service passed!") return "" } if r.expression == nil { log.Errorf("Invalid regex can't match using: %s", r.ServiceNameMatch) return container.Image } var svcName strin...
go
func (r *RegexpNamer) ServiceName(container *docker.APIContainers) string { if container == nil { log.Warn("ServiceName() called with nil service passed!") return "" } if r.expression == nil { log.Errorf("Invalid regex can't match using: %s", r.ServiceNameMatch) return container.Image } var svcName strin...
[ "func", "(", "r", "*", "RegexpNamer", ")", "ServiceName", "(", "container", "*", "docker", ".", "APIContainers", ")", "string", "{", "if", "container", "==", "nil", "{", "log", ".", "Warn", "(", "\"", "\"", ")", "\n", "return", "\"", "\"", "\n", "}",...
// Return a properly regex-matched name for the service, or failing that, // the Image ID which we use to stand in for the name of the service.
[ "Return", "a", "properly", "regex", "-", "matched", "name", "for", "the", "service", "or", "failing", "that", "the", "Image", "ID", "which", "we", "use", "to", "stand", "in", "for", "the", "name", "of", "the", "service", "." ]
8327834c20bca8a155ccac8bc42ab2f42ca925a6
https://github.com/newrelic/sidecar/blob/8327834c20bca8a155ccac8bc42ab2f42ca925a6/discovery/service_namer.go#L35-L57
11,832
newrelic/sidecar
discovery/service_namer.go
ServiceName
func (d *DockerLabelNamer) ServiceName(container *docker.APIContainers) string { if container == nil { log.Warn("ServiceName() called with nil service passed!") return "" } for label, value := range container.Labels { if label == d.Label { return value } } log.Debugf( "Found container with no '%s' l...
go
func (d *DockerLabelNamer) ServiceName(container *docker.APIContainers) string { if container == nil { log.Warn("ServiceName() called with nil service passed!") return "" } for label, value := range container.Labels { if label == d.Label { return value } } log.Debugf( "Found container with no '%s' l...
[ "func", "(", "d", "*", "DockerLabelNamer", ")", "ServiceName", "(", "container", "*", "docker", ".", "APIContainers", ")", "string", "{", "if", "container", "==", "nil", "{", "log", ".", "Warn", "(", "\"", "\"", ")", "\n", "return", "\"", "\"", "\n", ...
// Return the value of the configured Docker label, or default to the image // name.
[ "Return", "the", "value", "of", "the", "configured", "Docker", "label", "or", "default", "to", "the", "image", "name", "." ]
8327834c20bca8a155ccac8bc42ab2f42ca925a6
https://github.com/newrelic/sidecar/blob/8327834c20bca8a155ccac8bc42ab2f42ca925a6/discovery/service_namer.go#L67-L85
11,833
newrelic/sidecar
sidecarhttp/envoy_api_ffjson.go
UnmarshalJSON
func (j *EnvoyListener) UnmarshalJSON(input []byte) error { fs := fflib.NewFFLexer(input) return j.UnmarshalJSONFFLexer(fs, fflib.FFParse_map_start) }
go
func (j *EnvoyListener) UnmarshalJSON(input []byte) error { fs := fflib.NewFFLexer(input) return j.UnmarshalJSONFFLexer(fs, fflib.FFParse_map_start) }
[ "func", "(", "j", "*", "EnvoyListener", ")", "UnmarshalJSON", "(", "input", "[", "]", "byte", ")", "error", "{", "fs", ":=", "fflib", ".", "NewFFLexer", "(", "input", ")", "\n", "return", "j", ".", "UnmarshalJSONFFLexer", "(", "fs", ",", "fflib", ".", ...
// UnmarshalJSON umarshall json - template of ffjson
[ "UnmarshalJSON", "umarshall", "json", "-", "template", "of", "ffjson" ]
8327834c20bca8a155ccac8bc42ab2f42ca925a6
https://github.com/newrelic/sidecar/blob/8327834c20bca8a155ccac8bc42ab2f42ca925a6/sidecarhttp/envoy_api_ffjson.go#L2012-L2015
11,834
newrelic/sidecar
sidecarhttp/envoy_api_ffjson.go
MarshalJSON
func (j *EnvoyRoute) MarshalJSON() ([]byte, error) { var buf fflib.Buffer if j == nil { buf.WriteString("null") return buf.Bytes(), nil } err := j.MarshalJSONBuf(&buf) if err != nil { return nil, err } return buf.Bytes(), nil }
go
func (j *EnvoyRoute) MarshalJSON() ([]byte, error) { var buf fflib.Buffer if j == nil { buf.WriteString("null") return buf.Bytes(), nil } err := j.MarshalJSONBuf(&buf) if err != nil { return nil, err } return buf.Bytes(), nil }
[ "func", "(", "j", "*", "EnvoyRoute", ")", "MarshalJSON", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "var", "buf", "fflib", ".", "Buffer", "\n", "if", "j", "==", "nil", "{", "buf", ".", "WriteString", "(", "\"", "\"", ")", "\n", "r...
// MarshalJSON marshal bytes to json - template
[ "MarshalJSON", "marshal", "bytes", "to", "json", "-", "template" ]
8327834c20bca8a155ccac8bc42ab2f42ca925a6
https://github.com/newrelic/sidecar/blob/8327834c20bca8a155ccac8bc42ab2f42ca925a6/sidecarhttp/envoy_api_ffjson.go#L2301-L2312
11,835
newrelic/sidecar
services_delegate.go
Start
func (d *servicesDelegate) Start() { go func() { for message := range d.notifications { entry := service.Decode(message) if entry == nil { log.Errorf("NotifyMsg(): error decoding!") continue } d.state.ServiceMsgs <- *entry } }() d.Started = true d.StartedAt = time.Now().UTC() }
go
func (d *servicesDelegate) Start() { go func() { for message := range d.notifications { entry := service.Decode(message) if entry == nil { log.Errorf("NotifyMsg(): error decoding!") continue } d.state.ServiceMsgs <- *entry } }() d.Started = true d.StartedAt = time.Now().UTC() }
[ "func", "(", "d", "*", "servicesDelegate", ")", "Start", "(", ")", "{", "go", "func", "(", ")", "{", "for", "message", ":=", "range", "d", ".", "notifications", "{", "entry", ":=", "service", ".", "Decode", "(", "message", ")", "\n", "if", "entry", ...
// Start kicks off the goroutine that will process incoming notifications of services
[ "Start", "kicks", "off", "the", "goroutine", "that", "will", "process", "incoming", "notifications", "of", "services" ]
8327834c20bca8a155ccac8bc42ab2f42ca925a6
https://github.com/newrelic/sidecar/blob/8327834c20bca8a155ccac8bc42ab2f42ca925a6/services_delegate.go#L45-L59
11,836
newrelic/sidecar
services_delegate.go
packPacket
func (d *servicesDelegate) packPacket(broadcasts [][]byte, limit int, overhead int) (packet [][]byte, leftover [][]byte) { total := 0 lastItem := -1 // Find the index of the last item that fits into the packet we're building for i, message := range broadcasts { if total+len(message)+overhead > limit { break ...
go
func (d *servicesDelegate) packPacket(broadcasts [][]byte, limit int, overhead int) (packet [][]byte, leftover [][]byte) { total := 0 lastItem := -1 // Find the index of the last item that fits into the packet we're building for i, message := range broadcasts { if total+len(message)+overhead > limit { break ...
[ "func", "(", "d", "*", "servicesDelegate", ")", "packPacket", "(", "broadcasts", "[", "]", "[", "]", "byte", ",", "limit", "int", ",", "overhead", "int", ")", "(", "packet", "[", "]", "[", "]", "byte", ",", "leftover", "[", "]", "[", "]", "byte", ...
// Try to pack as many messages into the packet as we can. Note that this // assumes that no messages will be longer than the normal UDP packet size. // This means that max message length is somewhere around 1398 when taking // messaging overhead into account.
[ "Try", "to", "pack", "as", "many", "messages", "into", "the", "packet", "as", "we", "can", ".", "Note", "that", "this", "assumes", "that", "no", "messages", "will", "be", "longer", "than", "the", "normal", "UDP", "packet", "size", ".", "This", "means", ...
8327834c20bca8a155ccac8bc42ab2f42ca925a6
https://github.com/newrelic/sidecar/blob/8327834c20bca8a155ccac8bc42ab2f42ca925a6/services_delegate.go#L189-L222
11,837
newrelic/sidecar
service/service.go
Version
func (svc *Service) Version() string { parts := strings.Split(svc.Image, ":") if len(parts) > 1 { return parts[1] } return parts[0] }
go
func (svc *Service) Version() string { parts := strings.Split(svc.Image, ":") if len(parts) > 1 { return parts[1] } return parts[0] }
[ "func", "(", "svc", "*", "Service", ")", "Version", "(", ")", "string", "{", "parts", ":=", "strings", ".", "Split", "(", "svc", ".", "Image", ",", "\"", "\"", ")", "\n", "if", "len", "(", "parts", ")", ">", "1", "{", "return", "parts", "[", "1...
// Version attempts to extract a version from the image. Otherwise it returns // the full image name.
[ "Version", "attempts", "to", "extract", "a", "version", "from", "the", "image", ".", "Otherwise", "it", "returns", "the", "full", "image", "name", "." ]
8327834c20bca8a155ccac8bc42ab2f42ca925a6
https://github.com/newrelic/sidecar/blob/8327834c20bca8a155ccac8bc42ab2f42ca925a6/service/service.go#L104-L111
11,838
newrelic/sidecar
service/service.go
ToService
func ToService(container *docker.APIContainers, ip string) Service { var svc Service hostname, _ := os.Hostname() svc.ID = container.ID[0:12] // Use short IDs svc.Name = container.Names[0] // Use the first name svc.Image = container.Image svc.Created = time.Unix(container.Created, 0).UTC() svc.Updated = time....
go
func ToService(container *docker.APIContainers, ip string) Service { var svc Service hostname, _ := os.Hostname() svc.ID = container.ID[0:12] // Use short IDs svc.Name = container.Names[0] // Use the first name svc.Image = container.Image svc.Created = time.Unix(container.Created, 0).UTC() svc.Updated = time....
[ "func", "ToService", "(", "container", "*", "docker", ".", "APIContainers", ",", "ip", "string", ")", "Service", "{", "var", "svc", "Service", "\n", "hostname", ",", "_", ":=", "os", ".", "Hostname", "(", ")", "\n\n", "svc", ".", "ID", "=", "container"...
// Format an APIContainers struct into a more compact struct we // can ship over the wire in a broadcast.
[ "Format", "an", "APIContainers", "struct", "into", "a", "more", "compact", "struct", "we", "can", "ship", "over", "the", "wire", "in", "a", "broadcast", "." ]
8327834c20bca8a155ccac8bc42ab2f42ca925a6
https://github.com/newrelic/sidecar/blob/8327834c20bca8a155ccac8bc42ab2f42ca925a6/service/service.go#L122-L149
11,839
newrelic/sidecar
service/service.go
buildPortFor
func buildPortFor(port *docker.APIPort, container *docker.APIContainers, ip string) Port { // We look up service port labels by convention in the format "ServicePort_80=8080" svcPortLabel := fmt.Sprintf("ServicePort_%d", port.PrivatePort) // You can override the default IP by binding your container on a specific IP...
go
func buildPortFor(port *docker.APIPort, container *docker.APIContainers, ip string) Port { // We look up service port labels by convention in the format "ServicePort_80=8080" svcPortLabel := fmt.Sprintf("ServicePort_%d", port.PrivatePort) // You can override the default IP by binding your container on a specific IP...
[ "func", "buildPortFor", "(", "port", "*", "docker", ".", "APIPort", ",", "container", "*", "docker", ".", "APIContainers", ",", "ip", "string", ")", "Port", "{", "// We look up service port labels by convention in the format \"ServicePort_80=8080\"", "svcPortLabel", ":=",...
// Figure out the correct port configuration for a service
[ "Figure", "out", "the", "correct", "port", "configuration", "for", "a", "service" ]
8327834c20bca8a155ccac8bc42ab2f42ca925a6
https://github.com/newrelic/sidecar/blob/8327834c20bca8a155ccac8bc42ab2f42ca925a6/service/service.go#L165-L191
11,840
lytics/anomalyzer
anomalyze.go
Eval
func (a Anomalyzer) Eval() float64 { threshold := a.Conf.referenceSize + a.Conf.ActiveSize if a.Conf.Delay && len(a.Data) < threshold { return 0.0 } probmap := make(map[string]float64) for _, method := range a.Conf.Methods { algorithm := Algorithms[method] prob := cap(algorithm(a.Data, *a.Conf), 0, 1) if ...
go
func (a Anomalyzer) Eval() float64 { threshold := a.Conf.referenceSize + a.Conf.ActiveSize if a.Conf.Delay && len(a.Data) < threshold { return 0.0 } probmap := make(map[string]float64) for _, method := range a.Conf.Methods { algorithm := Algorithms[method] prob := cap(algorithm(a.Data, *a.Conf), 0, 1) if ...
[ "func", "(", "a", "Anomalyzer", ")", "Eval", "(", ")", "float64", "{", "threshold", ":=", "a", ".", "Conf", ".", "referenceSize", "+", "a", ".", "Conf", ".", "ActiveSize", "\n", "if", "a", ".", "Conf", ".", "Delay", "&&", "len", "(", "a", ".", "D...
// Return the weighted average of all statistical tests // for anomaly detection, which yields the probability that // the currently observed behavior is anomalous.
[ "Return", "the", "weighted", "average", "of", "all", "statistical", "tests", "for", "anomaly", "detection", "which", "yields", "the", "probability", "that", "the", "currently", "observed", "behavior", "is", "anomalous", "." ]
13cee106170131d4088721db299d09b42db508ac
https://github.com/lytics/anomalyzer/blob/13cee106170131d4088721db299d09b42db508ac/anomalyze.go#L145-L192
11,841
lytics/anomalyzer
anomalyze.go
getWeight
func (a Anomalyzer) getWeight(name string, prob float64) float64 { weight := 0.5 dynamicWeights := []string{"magnitude", "fence"} // If either the magnitude and fence methods don't have any // probability to contribute, we don't want to hear about it. // If they do, we upweight them substantially. if exists(name...
go
func (a Anomalyzer) getWeight(name string, prob float64) float64 { weight := 0.5 dynamicWeights := []string{"magnitude", "fence"} // If either the magnitude and fence methods don't have any // probability to contribute, we don't want to hear about it. // If they do, we upweight them substantially. if exists(name...
[ "func", "(", "a", "Anomalyzer", ")", "getWeight", "(", "name", "string", ",", "prob", "float64", ")", "float64", "{", "weight", ":=", "0.5", "\n\n", "dynamicWeights", ":=", "[", "]", "string", "{", "\"", "\"", ",", "\"", "\"", "}", "\n", "// If either ...
// Use essentially similar weights. However, if either the magnitude // or fence methods have high probabilities, upweight them significantly.
[ "Use", "essentially", "similar", "weights", ".", "However", "if", "either", "the", "magnitude", "or", "fence", "methods", "have", "high", "probabilities", "upweight", "them", "significantly", "." ]
13cee106170131d4088721db299d09b42db508ac
https://github.com/lytics/anomalyzer/blob/13cee106170131d4088721db299d09b42db508ac/anomalyze.go#L225-L241
11,842
lytics/anomalyzer
algorithms.go
extractWindows
func extractWindows(vector govector.Vector, refSize, activeSize, minRefSize int) (govector.Vector, govector.Vector, error) { n := len(vector) activeSize = min(activeSize, n) refSize = min(refSize, n-activeSize) // make sure the reference size is at least as big as the active size // note that this penalty might b...
go
func extractWindows(vector govector.Vector, refSize, activeSize, minRefSize int) (govector.Vector, govector.Vector, error) { n := len(vector) activeSize = min(activeSize, n) refSize = min(refSize, n-activeSize) // make sure the reference size is at least as big as the active size // note that this penalty might b...
[ "func", "extractWindows", "(", "vector", "govector", ".", "Vector", ",", "refSize", ",", "activeSize", ",", "minRefSize", "int", ")", "(", "govector", ".", "Vector", ",", "govector", ".", "Vector", ",", "error", ")", "{", "n", ":=", "len", "(", "vector",...
// Return a vector slice for the active window and reference window. // Some tests require different minimum thresholds for sizes of reference windows. // This can be specified in the minRefSize parameter. If size isn't important, use -1
[ "Return", "a", "vector", "slice", "for", "the", "active", "window", "and", "reference", "window", ".", "Some", "tests", "require", "different", "minimum", "thresholds", "for", "sizes", "of", "reference", "windows", ".", "This", "can", "be", "specified", "in", ...
13cee106170131d4088721db299d09b42db508ac
https://github.com/lytics/anomalyzer/blob/13cee106170131d4088721db299d09b42db508ac/algorithms.go#L56-L69
11,843
lytics/anomalyzer
algorithms.go
weightExp
func weightExp(x, base float64) float64 { return (math.Pow(base, x) - 1) / (math.Pow(base, 1) - 1) }
go
func weightExp(x, base float64) float64 { return (math.Pow(base, x) - 1) / (math.Pow(base, 1) - 1) }
[ "func", "weightExp", "(", "x", ",", "base", "float64", ")", "float64", "{", "return", "(", "math", ".", "Pow", "(", "base", ",", "x", ")", "-", "1", ")", "/", "(", "math", ".", "Pow", "(", "base", ",", "1", ")", "-", "1", ")", "\n", "}" ]
// This is a function will sharply scale values between 0 and 1 such that // smaller values are weighted more towards 0. A larger base value means a // more horshoe type function.
[ "This", "is", "a", "function", "will", "sharply", "scale", "values", "between", "0", "and", "1", "such", "that", "smaller", "values", "are", "weighted", "more", "towards", "0", ".", "A", "larger", "base", "value", "means", "a", "more", "horshoe", "type", ...
13cee106170131d4088721db299d09b42db508ac
https://github.com/lytics/anomalyzer/blob/13cee106170131d4088721db299d09b42db508ac/algorithms.go#L98-L100
11,844
lytics/anomalyzer
algorithms.go
KsStat
func KsStat(vector govector.Vector, conf AnomalyzerConf) float64 { reference, active, err := extractWindows(vector, conf.referenceSize, conf.ActiveSize, conf.ActiveSize) if err != nil { return NA } n1 := len(reference) n2 := len(active) if n1%n2 != 0 { return NA } // First sort the active data and generate...
go
func KsStat(vector govector.Vector, conf AnomalyzerConf) float64 { reference, active, err := extractWindows(vector, conf.referenceSize, conf.ActiveSize, conf.ActiveSize) if err != nil { return NA } n1 := len(reference) n2 := len(active) if n1%n2 != 0 { return NA } // First sort the active data and generate...
[ "func", "KsStat", "(", "vector", "govector", ".", "Vector", ",", "conf", "AnomalyzerConf", ")", "float64", "{", "reference", ",", "active", ",", "err", ":=", "extractWindows", "(", "vector", ",", "conf", ".", "referenceSize", ",", "conf", ".", "ActiveSize", ...
// Calculate a Kolmogorov-Smirnov test statistic.
[ "Calculate", "a", "Kolmogorov", "-", "Smirnov", "test", "statistic", "." ]
13cee106170131d4088721db299d09b42db508ac
https://github.com/lytics/anomalyzer/blob/13cee106170131d4088721db299d09b42db508ac/algorithms.go#L255-L288
11,845
lytics/anomalyzer
algorithms.go
interpolate
func interpolate(min, max float64, npoints int) govector.Vector { interp := make(govector.Vector, npoints) step := (max - min) / (float64(npoints) - 1) interp[0] = min i := 1 for i < npoints { interp[i] = interp[i-1] + step i++ } return interp }
go
func interpolate(min, max float64, npoints int) govector.Vector { interp := make(govector.Vector, npoints) step := (max - min) / (float64(npoints) - 1) interp[0] = min i := 1 for i < npoints { interp[i] = interp[i-1] + step i++ } return interp }
[ "func", "interpolate", "(", "min", ",", "max", "float64", ",", "npoints", "int", ")", "govector", ".", "Vector", "{", "interp", ":=", "make", "(", "govector", ".", "Vector", ",", "npoints", ")", "\n\n", "step", ":=", "(", "max", "-", "min", ")", "/",...
// A helper function for KS that rescales a vector to the desired length npoints.
[ "A", "helper", "function", "for", "KS", "that", "rescales", "a", "vector", "to", "the", "desired", "length", "npoints", "." ]
13cee106170131d4088721db299d09b42db508ac
https://github.com/lytics/anomalyzer/blob/13cee106170131d4088721db299d09b42db508ac/algorithms.go#L312-L323
11,846
liip/sheriff
sheriff.go
marshalValue
func marshalValue(options *Options, v reflect.Value) (interface{}, error) { // return nil on nil pointer struct fields if !v.IsValid() || !v.CanInterface() { return nil, nil } val := v.Interface() if marshaller, ok := val.(Marshaller); ok { return marshaller.Marshal(options) } // types which are e.g. struct...
go
func marshalValue(options *Options, v reflect.Value) (interface{}, error) { // return nil on nil pointer struct fields if !v.IsValid() || !v.CanInterface() { return nil, nil } val := v.Interface() if marshaller, ok := val.(Marshaller); ok { return marshaller.Marshal(options) } // types which are e.g. struct...
[ "func", "marshalValue", "(", "options", "*", "Options", ",", "v", "reflect", ".", "Value", ")", "(", "interface", "{", "}", ",", "error", ")", "{", "// return nil on nil pointer struct fields", "if", "!", "v", ".", "IsValid", "(", ")", "||", "!", "v", "....
// marshalValue is being used for getting the actual value of a field. // // There is support for types implementing the Marshaller interface, arbitrary structs, slices, maps and base types.
[ "marshalValue", "is", "being", "used", "for", "getting", "the", "actual", "value", "of", "a", "field", ".", "There", "is", "support", "for", "types", "implementing", "the", "Marshaller", "interface", "arbitrary", "structs", "slices", "maps", "and", "base", "ty...
91aa83a45a3d4550ade9b3f6ee70f10dc4e984ef
https://github.com/liip/sheriff/blob/91aa83a45a3d4550ade9b3f6ee70f10dc4e984ef/sheriff.go#L181-L240
11,847
liip/sheriff
sheriff.go
contains
func contains(key string, list []string) bool { for _, innerKey := range list { if key == innerKey { return true } } return false }
go
func contains(key string, list []string) bool { for _, innerKey := range list { if key == innerKey { return true } } return false }
[ "func", "contains", "(", "key", "string", ",", "list", "[", "]", "string", ")", "bool", "{", "for", "_", ",", "innerKey", ":=", "range", "list", "{", "if", "key", "==", "innerKey", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false...
// contains check if a given key is contained in a slice of strings.
[ "contains", "check", "if", "a", "given", "key", "is", "contained", "in", "a", "slice", "of", "strings", "." ]
91aa83a45a3d4550ade9b3f6ee70f10dc4e984ef
https://github.com/liip/sheriff/blob/91aa83a45a3d4550ade9b3f6ee70f10dc4e984ef/sheriff.go#L243-L250
11,848
liip/sheriff
sheriff.go
listContains
func listContains(a []string, b []string) bool { for _, key := range a { if contains(key, b) { return true } } return false }
go
func listContains(a []string, b []string) bool { for _, key := range a { if contains(key, b) { return true } } return false }
[ "func", "listContains", "(", "a", "[", "]", "string", ",", "b", "[", "]", "string", ")", "bool", "{", "for", "_", ",", "key", ":=", "range", "a", "{", "if", "contains", "(", "key", ",", "b", ")", "{", "return", "true", "\n", "}", "\n", "}", "...
// listContains operates on two string slices and checks if one of the strings in `a` // is contained in `b`.
[ "listContains", "operates", "on", "two", "string", "slices", "and", "checks", "if", "one", "of", "the", "strings", "in", "a", "is", "contained", "in", "b", "." ]
91aa83a45a3d4550ade9b3f6ee70f10dc4e984ef
https://github.com/liip/sheriff/blob/91aa83a45a3d4550ade9b3f6ee70f10dc4e984ef/sheriff.go#L254-L261
11,849
ybbus/jsonrpc
jsonrpc.go
Error
func (e *RPCError) Error() string { return strconv.Itoa(e.Code) + ":" + e.Message }
go
func (e *RPCError) Error() string { return strconv.Itoa(e.Code) + ":" + e.Message }
[ "func", "(", "e", "*", "RPCError", ")", "Error", "(", ")", "string", "{", "return", "strconv", ".", "Itoa", "(", "e", ".", "Code", ")", "+", "\"", "\"", "+", "e", ".", "Message", "\n", "}" ]
// Error function is provided to be used as error object.
[ "Error", "function", "is", "provided", "to", "be", "used", "as", "error", "object", "." ]
94088458a1e880219bd312fc0ccb8548993ebf80
https://github.com/ybbus/jsonrpc/blob/94088458a1e880219bd312fc0ccb8548993ebf80/jsonrpc.go#L207-L209
11,850
ybbus/jsonrpc
jsonrpc.go
AsMap
func (res RPCResponses) AsMap() map[int]*RPCResponse { resMap := make(map[int]*RPCResponse, 0) for _, r := range res { resMap[r.ID] = r } return resMap }
go
func (res RPCResponses) AsMap() map[int]*RPCResponse { resMap := make(map[int]*RPCResponse, 0) for _, r := range res { resMap[r.ID] = r } return resMap }
[ "func", "(", "res", "RPCResponses", ")", "AsMap", "(", ")", "map", "[", "int", "]", "*", "RPCResponse", "{", "resMap", ":=", "make", "(", "map", "[", "int", "]", "*", "RPCResponse", ",", "0", ")", "\n", "for", "_", ",", "r", ":=", "range", "res",...
// AsMap returns the responses as map with response id as key.
[ "AsMap", "returns", "the", "responses", "as", "map", "with", "response", "id", "as", "key", "." ]
94088458a1e880219bd312fc0ccb8548993ebf80
https://github.com/ybbus/jsonrpc/blob/94088458a1e880219bd312fc0ccb8548993ebf80/jsonrpc.go#L248-L255
11,851
ybbus/jsonrpc
jsonrpc.go
GetByID
func (res RPCResponses) GetByID(id int) *RPCResponse { for _, r := range res { if r.ID == id { return r } } return nil }
go
func (res RPCResponses) GetByID(id int) *RPCResponse { for _, r := range res { if r.ID == id { return r } } return nil }
[ "func", "(", "res", "RPCResponses", ")", "GetByID", "(", "id", "int", ")", "*", "RPCResponse", "{", "for", "_", ",", "r", ":=", "range", "res", "{", "if", "r", ".", "ID", "==", "id", "{", "return", "r", "\n", "}", "\n", "}", "\n\n", "return", "...
// GetByID returns the response object of the given id, nil if it does not exist.
[ "GetByID", "returns", "the", "response", "object", "of", "the", "given", "id", "nil", "if", "it", "does", "not", "exist", "." ]
94088458a1e880219bd312fc0ccb8548993ebf80
https://github.com/ybbus/jsonrpc/blob/94088458a1e880219bd312fc0ccb8548993ebf80/jsonrpc.go#L258-L266
11,852
ybbus/jsonrpc
jsonrpc.go
HasError
func (res RPCResponses) HasError() bool { for _, res := range res { if res.Error != nil { return true } } return false }
go
func (res RPCResponses) HasError() bool { for _, res := range res { if res.Error != nil { return true } } return false }
[ "func", "(", "res", "RPCResponses", ")", "HasError", "(", ")", "bool", "{", "for", "_", ",", "res", ":=", "range", "res", "{", "if", "res", ".", "Error", "!=", "nil", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}"...
// HasError returns true if one of the response objects has Error field != nil
[ "HasError", "returns", "true", "if", "one", "of", "the", "response", "objects", "has", "Error", "field", "!", "=", "nil" ]
94088458a1e880219bd312fc0ccb8548993ebf80
https://github.com/ybbus/jsonrpc/blob/94088458a1e880219bd312fc0ccb8548993ebf80/jsonrpc.go#L269-L276
11,853
ybbus/jsonrpc
jsonrpc.go
GetInt
func (RPCResponse *RPCResponse) GetInt() (int64, error) { val, ok := RPCResponse.Result.(json.Number) if !ok { return 0, fmt.Errorf("could not parse int64 from %s", RPCResponse.Result) } i, err := val.Int64() if err != nil { return 0, err } return i, nil }
go
func (RPCResponse *RPCResponse) GetInt() (int64, error) { val, ok := RPCResponse.Result.(json.Number) if !ok { return 0, fmt.Errorf("could not parse int64 from %s", RPCResponse.Result) } i, err := val.Int64() if err != nil { return 0, err } return i, nil }
[ "func", "(", "RPCResponse", "*", "RPCResponse", ")", "GetInt", "(", ")", "(", "int64", ",", "error", ")", "{", "val", ",", "ok", ":=", "RPCResponse", ".", "Result", ".", "(", "json", ".", "Number", ")", "\n", "if", "!", "ok", "{", "return", "0", ...
// GetInt converts the rpc response to an int64 and returns it. // // If result was not an integer an error is returned.
[ "GetInt", "converts", "the", "rpc", "response", "to", "an", "int64", "and", "returns", "it", ".", "If", "result", "was", "not", "an", "integer", "an", "error", "is", "returned", "." ]
94088458a1e880219bd312fc0ccb8548993ebf80
https://github.com/ybbus/jsonrpc/blob/94088458a1e880219bd312fc0ccb8548993ebf80/jsonrpc.go#L550-L562
11,854
ybbus/jsonrpc
jsonrpc.go
GetFloat
func (RPCResponse *RPCResponse) GetFloat() (float64, error) { val, ok := RPCResponse.Result.(json.Number) if !ok { return 0, fmt.Errorf("could not parse float64 from %s", RPCResponse.Result) } f, err := val.Float64() if err != nil { return 0, err } return f, nil }
go
func (RPCResponse *RPCResponse) GetFloat() (float64, error) { val, ok := RPCResponse.Result.(json.Number) if !ok { return 0, fmt.Errorf("could not parse float64 from %s", RPCResponse.Result) } f, err := val.Float64() if err != nil { return 0, err } return f, nil }
[ "func", "(", "RPCResponse", "*", "RPCResponse", ")", "GetFloat", "(", ")", "(", "float64", ",", "error", ")", "{", "val", ",", "ok", ":=", "RPCResponse", ".", "Result", ".", "(", "json", ".", "Number", ")", "\n", "if", "!", "ok", "{", "return", "0"...
// GetFloat converts the rpc response to float64 and returns it. // // If result was not an float64 an error is returned.
[ "GetFloat", "converts", "the", "rpc", "response", "to", "float64", "and", "returns", "it", ".", "If", "result", "was", "not", "an", "float64", "an", "error", "is", "returned", "." ]
94088458a1e880219bd312fc0ccb8548993ebf80
https://github.com/ybbus/jsonrpc/blob/94088458a1e880219bd312fc0ccb8548993ebf80/jsonrpc.go#L567-L579
11,855
ybbus/jsonrpc
jsonrpc.go
GetBool
func (RPCResponse *RPCResponse) GetBool() (bool, error) { val, ok := RPCResponse.Result.(bool) if !ok { return false, fmt.Errorf("could not parse bool from %s", RPCResponse.Result) } return val, nil }
go
func (RPCResponse *RPCResponse) GetBool() (bool, error) { val, ok := RPCResponse.Result.(bool) if !ok { return false, fmt.Errorf("could not parse bool from %s", RPCResponse.Result) } return val, nil }
[ "func", "(", "RPCResponse", "*", "RPCResponse", ")", "GetBool", "(", ")", "(", "bool", ",", "error", ")", "{", "val", ",", "ok", ":=", "RPCResponse", ".", "Result", ".", "(", "bool", ")", "\n", "if", "!", "ok", "{", "return", "false", ",", "fmt", ...
// GetBool converts the rpc response to a bool and returns it. // // If result was not a bool an error is returned.
[ "GetBool", "converts", "the", "rpc", "response", "to", "a", "bool", "and", "returns", "it", ".", "If", "result", "was", "not", "a", "bool", "an", "error", "is", "returned", "." ]
94088458a1e880219bd312fc0ccb8548993ebf80
https://github.com/ybbus/jsonrpc/blob/94088458a1e880219bd312fc0ccb8548993ebf80/jsonrpc.go#L584-L591
11,856
ybbus/jsonrpc
jsonrpc.go
GetString
func (RPCResponse *RPCResponse) GetString() (string, error) { val, ok := RPCResponse.Result.(string) if !ok { return "", fmt.Errorf("could not parse string from %s", RPCResponse.Result) } return val, nil }
go
func (RPCResponse *RPCResponse) GetString() (string, error) { val, ok := RPCResponse.Result.(string) if !ok { return "", fmt.Errorf("could not parse string from %s", RPCResponse.Result) } return val, nil }
[ "func", "(", "RPCResponse", "*", "RPCResponse", ")", "GetString", "(", ")", "(", "string", ",", "error", ")", "{", "val", ",", "ok", ":=", "RPCResponse", ".", "Result", ".", "(", "string", ")", "\n", "if", "!", "ok", "{", "return", "\"", "\"", ",",...
// GetString converts the rpc response to a string and returns it. // // If result was not a string an error is returned.
[ "GetString", "converts", "the", "rpc", "response", "to", "a", "string", "and", "returns", "it", ".", "If", "result", "was", "not", "a", "string", "an", "error", "is", "returned", "." ]
94088458a1e880219bd312fc0ccb8548993ebf80
https://github.com/ybbus/jsonrpc/blob/94088458a1e880219bd312fc0ccb8548993ebf80/jsonrpc.go#L596-L603
11,857
lightningnetwork/lightning-onion
batch.go
NewBatch
func NewBatch(id []byte) *Batch { return &Batch{ ID: id, ReplaySet: NewReplaySet(), entries: make(map[uint16]batchEntry), replayCache: make(map[HashPrefix]struct{}), } }
go
func NewBatch(id []byte) *Batch { return &Batch{ ID: id, ReplaySet: NewReplaySet(), entries: make(map[uint16]batchEntry), replayCache: make(map[HashPrefix]struct{}), } }
[ "func", "NewBatch", "(", "id", "[", "]", "byte", ")", "*", "Batch", "{", "return", "&", "Batch", "{", "ID", ":", "id", ",", "ReplaySet", ":", "NewReplaySet", "(", ")", ",", "entries", ":", "make", "(", "map", "[", "uint16", "]", "batchEntry", ")", ...
// NewBatch initializes an object for constructing a set of entries to // atomically add to a replay log. Batches are identified by byte slice, which // allows the caller to safely process the same batch twice and get an // idempotent result.
[ "NewBatch", "initializes", "an", "object", "for", "constructing", "a", "set", "of", "entries", "to", "atomically", "add", "to", "a", "replay", "log", ".", "Batches", "are", "identified", "by", "byte", "slice", "which", "allows", "the", "caller", "to", "safel...
751fb4dd8b72bbaec93889249a6c6ca9f71a5598
https://github.com/lightningnetwork/lightning-onion/blob/751fb4dd8b72bbaec93889249a6c6ca9f71a5598/batch.go#L41-L48
11,858
lightningnetwork/lightning-onion
batch.go
ForEach
func (b *Batch) ForEach(fn func(seqNum uint16, hashPrefix *HashPrefix, cltv uint32) error) error { for seqNum, entry := range b.entries { if err := fn(seqNum, &entry.hashPrefix, entry.cltv); err != nil { return err } } return nil }
go
func (b *Batch) ForEach(fn func(seqNum uint16, hashPrefix *HashPrefix, cltv uint32) error) error { for seqNum, entry := range b.entries { if err := fn(seqNum, &entry.hashPrefix, entry.cltv); err != nil { return err } } return nil }
[ "func", "(", "b", "*", "Batch", ")", "ForEach", "(", "fn", "func", "(", "seqNum", "uint16", ",", "hashPrefix", "*", "HashPrefix", ",", "cltv", "uint32", ")", "error", ")", "error", "{", "for", "seqNum", ",", "entry", ":=", "range", "b", ".", "entries...
// ForEach iterates through each entry in the batch and calls the provided // function with the sequence number and entry contents as arguments.
[ "ForEach", "iterates", "through", "each", "entry", "in", "the", "batch", "and", "calls", "the", "provided", "function", "with", "the", "sequence", "number", "and", "entry", "contents", "as", "arguments", "." ]
751fb4dd8b72bbaec93889249a6c6ca9f71a5598
https://github.com/lightningnetwork/lightning-onion/blob/751fb4dd8b72bbaec93889249a6c6ca9f71a5598/batch.go#L86-L93
11,859
lightningnetwork/lightning-onion
replaylog.go
hashSharedSecret
func hashSharedSecret(sharedSecret *Hash256) *HashPrefix { // Sha256 hash of sharedSecret h := sha256.New() h.Write(sharedSecret[:]) var sharedHash HashPrefix // Copy bytes to sharedHash copy(sharedHash[:], h.Sum(nil)) return &sharedHash }
go
func hashSharedSecret(sharedSecret *Hash256) *HashPrefix { // Sha256 hash of sharedSecret h := sha256.New() h.Write(sharedSecret[:]) var sharedHash HashPrefix // Copy bytes to sharedHash copy(sharedHash[:], h.Sum(nil)) return &sharedHash }
[ "func", "hashSharedSecret", "(", "sharedSecret", "*", "Hash256", ")", "*", "HashPrefix", "{", "// Sha256 hash of sharedSecret", "h", ":=", "sha256", ".", "New", "(", ")", "\n", "h", ".", "Write", "(", "sharedSecret", "[", ":", "]", ")", "\n\n", "var", "sha...
// hashSharedSecret Sha-256 hashes the shared secret and returns the first // HashPrefixSize bytes of the hash.
[ "hashSharedSecret", "Sha", "-", "256", "hashes", "the", "shared", "secret", "and", "returns", "the", "first", "HashPrefixSize", "bytes", "of", "the", "hash", "." ]
751fb4dd8b72bbaec93889249a6c6ca9f71a5598
https://github.com/lightningnetwork/lightning-onion/blob/751fb4dd8b72bbaec93889249a6c6ca9f71a5598/replaylog.go#L31-L41
11,860
lightningnetwork/lightning-onion
replaylog.go
Start
func (rl *MemoryReplayLog) Start() error { rl.batches = make(map[string]*ReplaySet) rl.entries = make(map[HashPrefix]uint32) return nil }
go
func (rl *MemoryReplayLog) Start() error { rl.batches = make(map[string]*ReplaySet) rl.entries = make(map[HashPrefix]uint32) return nil }
[ "func", "(", "rl", "*", "MemoryReplayLog", ")", "Start", "(", ")", "error", "{", "rl", ".", "batches", "=", "make", "(", "map", "[", "string", "]", "*", "ReplaySet", ")", "\n", "rl", ".", "entries", "=", "make", "(", "map", "[", "HashPrefix", "]", ...
// Start initializes the log and must be called before any other methods.
[ "Start", "initializes", "the", "log", "and", "must", "be", "called", "before", "any", "other", "methods", "." ]
751fb4dd8b72bbaec93889249a6c6ca9f71a5598
https://github.com/lightningnetwork/lightning-onion/blob/751fb4dd8b72bbaec93889249a6c6ca9f71a5598/replaylog.go#L88-L92
11,861
lightningnetwork/lightning-onion
replaylog.go
Stop
func (rl *MemoryReplayLog) Stop() error { if rl.entries == nil || rl.batches == nil { return errReplayLogNotStarted } rl.batches = nil rl.entries = nil return nil }
go
func (rl *MemoryReplayLog) Stop() error { if rl.entries == nil || rl.batches == nil { return errReplayLogNotStarted } rl.batches = nil rl.entries = nil return nil }
[ "func", "(", "rl", "*", "MemoryReplayLog", ")", "Stop", "(", ")", "error", "{", "if", "rl", ".", "entries", "==", "nil", "||", "rl", ".", "batches", "==", "nil", "{", "return", "errReplayLogNotStarted", "\n", "}", "\n\n", "rl", ".", "batches", "=", "...
// Stop wipes the state of the log.
[ "Stop", "wipes", "the", "state", "of", "the", "log", "." ]
751fb4dd8b72bbaec93889249a6c6ca9f71a5598
https://github.com/lightningnetwork/lightning-onion/blob/751fb4dd8b72bbaec93889249a6c6ca9f71a5598/replaylog.go#L95-L103
11,862
lightningnetwork/lightning-onion
replaylog.go
Get
func (rl *MemoryReplayLog) Get(hash *HashPrefix) (uint32, error) { if rl.entries == nil || rl.batches == nil { return 0, errReplayLogNotStarted } cltv, exists := rl.entries[*hash] if !exists { return 0, ErrLogEntryNotFound } return cltv, nil }
go
func (rl *MemoryReplayLog) Get(hash *HashPrefix) (uint32, error) { if rl.entries == nil || rl.batches == nil { return 0, errReplayLogNotStarted } cltv, exists := rl.entries[*hash] if !exists { return 0, ErrLogEntryNotFound } return cltv, nil }
[ "func", "(", "rl", "*", "MemoryReplayLog", ")", "Get", "(", "hash", "*", "HashPrefix", ")", "(", "uint32", ",", "error", ")", "{", "if", "rl", ".", "entries", "==", "nil", "||", "rl", ".", "batches", "==", "nil", "{", "return", "0", ",", "errReplay...
// Get retrieves an entry from the log given its hash prefix. It returns the // value stored and an error if one occurs. It returns ErrLogEntryNotFound // if the entry is not in the log.
[ "Get", "retrieves", "an", "entry", "from", "the", "log", "given", "its", "hash", "prefix", ".", "It", "returns", "the", "value", "stored", "and", "an", "error", "if", "one", "occurs", ".", "It", "returns", "ErrLogEntryNotFound", "if", "the", "entry", "is",...
751fb4dd8b72bbaec93889249a6c6ca9f71a5598
https://github.com/lightningnetwork/lightning-onion/blob/751fb4dd8b72bbaec93889249a6c6ca9f71a5598/replaylog.go#L108-L119
11,863
lightningnetwork/lightning-onion
replaylog.go
Put
func (rl *MemoryReplayLog) Put(hash *HashPrefix, cltv uint32) error { if rl.entries == nil || rl.batches == nil { return errReplayLogNotStarted } _, exists := rl.entries[*hash] if exists { return ErrReplayedPacket } rl.entries[*hash] = cltv return nil }
go
func (rl *MemoryReplayLog) Put(hash *HashPrefix, cltv uint32) error { if rl.entries == nil || rl.batches == nil { return errReplayLogNotStarted } _, exists := rl.entries[*hash] if exists { return ErrReplayedPacket } rl.entries[*hash] = cltv return nil }
[ "func", "(", "rl", "*", "MemoryReplayLog", ")", "Put", "(", "hash", "*", "HashPrefix", ",", "cltv", "uint32", ")", "error", "{", "if", "rl", ".", "entries", "==", "nil", "||", "rl", ".", "batches", "==", "nil", "{", "return", "errReplayLogNotStarted", ...
// Put stores an entry into the log given its hash prefix and an accompanying // purposefully general type. It returns ErrReplayedPacket if the provided hash // prefix already exists in the log.
[ "Put", "stores", "an", "entry", "into", "the", "log", "given", "its", "hash", "prefix", "and", "an", "accompanying", "purposefully", "general", "type", ".", "It", "returns", "ErrReplayedPacket", "if", "the", "provided", "hash", "prefix", "already", "exists", "...
751fb4dd8b72bbaec93889249a6c6ca9f71a5598
https://github.com/lightningnetwork/lightning-onion/blob/751fb4dd8b72bbaec93889249a6c6ca9f71a5598/replaylog.go#L124-L136
11,864
lightningnetwork/lightning-onion
replaylog.go
Delete
func (rl *MemoryReplayLog) Delete(hash *HashPrefix) error { if rl.entries == nil || rl.batches == nil { return errReplayLogNotStarted } delete(rl.entries, *hash) return nil }
go
func (rl *MemoryReplayLog) Delete(hash *HashPrefix) error { if rl.entries == nil || rl.batches == nil { return errReplayLogNotStarted } delete(rl.entries, *hash) return nil }
[ "func", "(", "rl", "*", "MemoryReplayLog", ")", "Delete", "(", "hash", "*", "HashPrefix", ")", "error", "{", "if", "rl", ".", "entries", "==", "nil", "||", "rl", ".", "batches", "==", "nil", "{", "return", "errReplayLogNotStarted", "\n", "}", "\n\n", "...
// Delete deletes an entry from the log given its hash prefix.
[ "Delete", "deletes", "an", "entry", "from", "the", "log", "given", "its", "hash", "prefix", "." ]
751fb4dd8b72bbaec93889249a6c6ca9f71a5598
https://github.com/lightningnetwork/lightning-onion/blob/751fb4dd8b72bbaec93889249a6c6ca9f71a5598/replaylog.go#L139-L146
11,865
lightningnetwork/lightning-onion
replaylog.go
PutBatch
func (rl *MemoryReplayLog) PutBatch(batch *Batch) (*ReplaySet, error) { if rl.entries == nil || rl.batches == nil { return nil, errReplayLogNotStarted } // Return the result when the batch was first processed to provide // idempotence. replays, exists := rl.batches[string(batch.ID)] if !exists { replays = N...
go
func (rl *MemoryReplayLog) PutBatch(batch *Batch) (*ReplaySet, error) { if rl.entries == nil || rl.batches == nil { return nil, errReplayLogNotStarted } // Return the result when the batch was first processed to provide // idempotence. replays, exists := rl.batches[string(batch.ID)] if !exists { replays = N...
[ "func", "(", "rl", "*", "MemoryReplayLog", ")", "PutBatch", "(", "batch", "*", "Batch", ")", "(", "*", "ReplaySet", ",", "error", ")", "{", "if", "rl", ".", "entries", "==", "nil", "||", "rl", ".", "batches", "==", "nil", "{", "return", "nil", ",",...
// PutBatch stores a batch of sphinx packets into the log given their hash // prefixes and accompanying values. Returns the set of entries in the batch // that are replays and an error if one occurs.
[ "PutBatch", "stores", "a", "batch", "of", "sphinx", "packets", "into", "the", "log", "given", "their", "hash", "prefixes", "and", "accompanying", "values", ".", "Returns", "the", "set", "of", "entries", "in", "the", "batch", "that", "are", "replays", "and", ...
751fb4dd8b72bbaec93889249a6c6ca9f71a5598
https://github.com/lightningnetwork/lightning-onion/blob/751fb4dd8b72bbaec93889249a6c6ca9f71a5598/replaylog.go#L151-L185
11,866
lightningnetwork/lightning-onion
cmd/main.go
main
func main() { args := os.Args assocData := bytes.Repeat([]byte{'B'}, 32) if len(args) == 1 { fmt.Printf("Usage: %s (generate|decode) <private-keys>\n", args[0]) } else if args[1] == "generate" { var path sphinx.PaymentPath for i, hexKey := range args[2:] { binKey, err := hex.DecodeString(hexKey) if er...
go
func main() { args := os.Args assocData := bytes.Repeat([]byte{'B'}, 32) if len(args) == 1 { fmt.Printf("Usage: %s (generate|decode) <private-keys>\n", args[0]) } else if args[1] == "generate" { var path sphinx.PaymentPath for i, hexKey := range args[2:] { binKey, err := hex.DecodeString(hexKey) if er...
[ "func", "main", "(", ")", "{", "args", ":=", "os", ".", "Args", "\n\n", "assocData", ":=", "bytes", ".", "Repeat", "(", "[", "]", "byte", "{", "'B'", "}", ",", "32", ")", "\n\n", "if", "len", "(", "args", ")", "==", "1", "{", "fmt", ".", "Pri...
// main implements a simple command line utility that can be used in order to // either generate a fresh mix-header or decode and fully process an existing // one given a private key.
[ "main", "implements", "a", "simple", "command", "line", "utility", "that", "can", "be", "used", "in", "order", "to", "either", "generate", "a", "fresh", "mix", "-", "header", "or", "decode", "and", "fully", "process", "an", "existing", "one", "given", "a",...
751fb4dd8b72bbaec93889249a6c6ca9f71a5598
https://github.com/lightningnetwork/lightning-onion/blob/751fb4dd8b72bbaec93889249a6c6ca9f71a5598/cmd/main.go#L20-L103
11,867
lightningnetwork/lightning-onion
sphinx.go
Encode
func (hd *HopData) Encode(w io.Writer) error { if _, err := w.Write(hd.Realm[:]); err != nil { return err } if _, err := w.Write(hd.NextAddress[:]); err != nil { return err } if err := binary.Write(w, binary.BigEndian, hd.ForwardAmount); err != nil { return err } if err := binary.Write(w, binary.BigEndi...
go
func (hd *HopData) Encode(w io.Writer) error { if _, err := w.Write(hd.Realm[:]); err != nil { return err } if _, err := w.Write(hd.NextAddress[:]); err != nil { return err } if err := binary.Write(w, binary.BigEndian, hd.ForwardAmount); err != nil { return err } if err := binary.Write(w, binary.BigEndi...
[ "func", "(", "hd", "*", "HopData", ")", "Encode", "(", "w", "io", ".", "Writer", ")", "error", "{", "if", "_", ",", "err", ":=", "w", ".", "Write", "(", "hd", ".", "Realm", "[", ":", "]", ")", ";", "err", "!=", "nil", "{", "return", "err", ...
// Encode writes the serialized version of the target HopData into the passed // io.Writer.
[ "Encode", "writes", "the", "serialized", "version", "of", "the", "target", "HopData", "into", "the", "passed", "io", ".", "Writer", "." ]
751fb4dd8b72bbaec93889249a6c6ca9f71a5598
https://github.com/lightningnetwork/lightning-onion/blob/751fb4dd8b72bbaec93889249a6c6ca9f71a5598/sphinx.go#L147-L173
11,868
lightningnetwork/lightning-onion
sphinx.go
Decode
func (hd *HopData) Decode(r io.Reader) error { if _, err := io.ReadFull(r, hd.Realm[:]); err != nil { return err } if _, err := io.ReadFull(r, hd.NextAddress[:]); err != nil { return err } if err := binary.Read(r, binary.BigEndian, &hd.ForwardAmount); err != nil { return err } if err := binary.Read(r, b...
go
func (hd *HopData) Decode(r io.Reader) error { if _, err := io.ReadFull(r, hd.Realm[:]); err != nil { return err } if _, err := io.ReadFull(r, hd.NextAddress[:]); err != nil { return err } if err := binary.Read(r, binary.BigEndian, &hd.ForwardAmount); err != nil { return err } if err := binary.Read(r, b...
[ "func", "(", "hd", "*", "HopData", ")", "Decode", "(", "r", "io", ".", "Reader", ")", "error", "{", "if", "_", ",", "err", ":=", "io", ".", "ReadFull", "(", "r", ",", "hd", ".", "Realm", "[", ":", "]", ")", ";", "err", "!=", "nil", "{", "re...
// Decode deserializes the encoded HopData contained int he passed io.Reader // instance to the target empty HopData instance.
[ "Decode", "deserializes", "the", "encoded", "HopData", "contained", "int", "he", "passed", "io", ".", "Reader", "instance", "to", "the", "target", "empty", "HopData", "instance", "." ]
751fb4dd8b72bbaec93889249a6c6ca9f71a5598
https://github.com/lightningnetwork/lightning-onion/blob/751fb4dd8b72bbaec93889249a6c6ca9f71a5598/sphinx.go#L177-L203
11,869
lightningnetwork/lightning-onion
sphinx.go
generateSharedSecrets
func generateSharedSecrets(paymentPath []*btcec.PublicKey, sessionKey *btcec.PrivateKey) []Hash256 { // Each hop performs ECDH with our ephemeral key pair to arrive at a // shared secret. Additionally, each hop randomizes the group element // for the next hop by multiplying it by the blinding factor. This way // ...
go
func generateSharedSecrets(paymentPath []*btcec.PublicKey, sessionKey *btcec.PrivateKey) []Hash256 { // Each hop performs ECDH with our ephemeral key pair to arrive at a // shared secret. Additionally, each hop randomizes the group element // for the next hop by multiplying it by the blinding factor. This way // ...
[ "func", "generateSharedSecrets", "(", "paymentPath", "[", "]", "*", "btcec", ".", "PublicKey", ",", "sessionKey", "*", "btcec", ".", "PrivateKey", ")", "[", "]", "Hash256", "{", "// Each hop performs ECDH with our ephemeral key pair to arrive at a", "// shared secret. Add...
// generateSharedSecrets by the given nodes pubkeys, generates the shared // secrets.
[ "generateSharedSecrets", "by", "the", "given", "nodes", "pubkeys", "generates", "the", "shared", "secrets", "." ]
751fb4dd8b72bbaec93889249a6c6ca9f71a5598
https://github.com/lightningnetwork/lightning-onion/blob/751fb4dd8b72bbaec93889249a6c6ca9f71a5598/sphinx.go#L207-L276
11,870
lightningnetwork/lightning-onion
sphinx.go
NewOnionPacket
func NewOnionPacket(paymentPath *PaymentPath, sessionKey *btcec.PrivateKey, assocData []byte) (*OnionPacket, error) { numHops := paymentPath.TrueRouteLength() hopSharedSecrets := generateSharedSecrets( paymentPath.NodeKeys(), sessionKey, ) // Generate the padding, called "filler strings" in the paper. filler...
go
func NewOnionPacket(paymentPath *PaymentPath, sessionKey *btcec.PrivateKey, assocData []byte) (*OnionPacket, error) { numHops := paymentPath.TrueRouteLength() hopSharedSecrets := generateSharedSecrets( paymentPath.NodeKeys(), sessionKey, ) // Generate the padding, called "filler strings" in the paper. filler...
[ "func", "NewOnionPacket", "(", "paymentPath", "*", "PaymentPath", ",", "sessionKey", "*", "btcec", ".", "PrivateKey", ",", "assocData", "[", "]", "byte", ")", "(", "*", "OnionPacket", ",", "error", ")", "{", "numHops", ":=", "paymentPath", ".", "TrueRouteLen...
// NewOnionPacket creates a new onion packet which is capable of obliviously // routing a message through the mix-net path outline by 'paymentPath'.
[ "NewOnionPacket", "creates", "a", "new", "onion", "packet", "which", "is", "capable", "of", "obliviously", "routing", "a", "message", "through", "the", "mix", "-", "net", "path", "outline", "by", "paymentPath", "." ]
751fb4dd8b72bbaec93889249a6c6ca9f71a5598
https://github.com/lightningnetwork/lightning-onion/blob/751fb4dd8b72bbaec93889249a6c6ca9f71a5598/sphinx.go#L280-L362
11,871
lightningnetwork/lightning-onion
sphinx.go
rightShift
func rightShift(slice []byte, num int) { for i := len(slice) - num - 1; i >= 0; i-- { slice[num+i] = slice[i] } for i := 0; i < num; i++ { slice[i] = 0 } }
go
func rightShift(slice []byte, num int) { for i := len(slice) - num - 1; i >= 0; i-- { slice[num+i] = slice[i] } for i := 0; i < num; i++ { slice[i] = 0 } }
[ "func", "rightShift", "(", "slice", "[", "]", "byte", ",", "num", "int", ")", "{", "for", "i", ":=", "len", "(", "slice", ")", "-", "num", "-", "1", ";", "i", ">=", "0", ";", "i", "--", "{", "slice", "[", "num", "+", "i", "]", "=", "slice",...
// rightShift shifts the byte-slice by the given number of bytes to the right // and 0-fill the resulting gap.
[ "rightShift", "shifts", "the", "byte", "-", "slice", "by", "the", "given", "number", "of", "bytes", "to", "the", "right", "and", "0", "-", "fill", "the", "resulting", "gap", "." ]
751fb4dd8b72bbaec93889249a6c6ca9f71a5598
https://github.com/lightningnetwork/lightning-onion/blob/751fb4dd8b72bbaec93889249a6c6ca9f71a5598/sphinx.go#L366-L374
11,872
lightningnetwork/lightning-onion
sphinx.go
Encode
func (f *OnionPacket) Encode(w io.Writer) error { ephemeral := f.EphemeralKey.SerializeCompressed() if _, err := w.Write([]byte{f.Version}); err != nil { return err } if _, err := w.Write(ephemeral); err != nil { return err } if _, err := w.Write(f.RoutingInfo[:]); err != nil { return err } if _, err ...
go
func (f *OnionPacket) Encode(w io.Writer) error { ephemeral := f.EphemeralKey.SerializeCompressed() if _, err := w.Write([]byte{f.Version}); err != nil { return err } if _, err := w.Write(ephemeral); err != nil { return err } if _, err := w.Write(f.RoutingInfo[:]); err != nil { return err } if _, err ...
[ "func", "(", "f", "*", "OnionPacket", ")", "Encode", "(", "w", "io", ".", "Writer", ")", "error", "{", "ephemeral", ":=", "f", ".", "EphemeralKey", ".", "SerializeCompressed", "(", ")", "\n\n", "if", "_", ",", "err", ":=", "w", ".", "Write", "(", "...
// Encode serializes the raw bytes of the onion packet into the passed // io.Writer. The form encoded within the passed io.Writer is suitable for // either storing on disk, or sending over the network.
[ "Encode", "serializes", "the", "raw", "bytes", "of", "the", "onion", "packet", "into", "the", "passed", "io", ".", "Writer", ".", "The", "form", "encoded", "within", "the", "passed", "io", ".", "Writer", "is", "suitable", "for", "either", "storing", "on", ...
751fb4dd8b72bbaec93889249a6c6ca9f71a5598
https://github.com/lightningnetwork/lightning-onion/blob/751fb4dd8b72bbaec93889249a6c6ca9f71a5598/sphinx.go#L404-L424
11,873
lightningnetwork/lightning-onion
sphinx.go
Decode
func (f *OnionPacket) Decode(r io.Reader) error { var err error var buf [1]byte if _, err := io.ReadFull(r, buf[:]); err != nil { return err } f.Version = buf[0] // If version of the onion packet protocol unknown for us than in might // lead to improperly decoded data. if f.Version != baseVersion { return...
go
func (f *OnionPacket) Decode(r io.Reader) error { var err error var buf [1]byte if _, err := io.ReadFull(r, buf[:]); err != nil { return err } f.Version = buf[0] // If version of the onion packet protocol unknown for us than in might // lead to improperly decoded data. if f.Version != baseVersion { return...
[ "func", "(", "f", "*", "OnionPacket", ")", "Decode", "(", "r", "io", ".", "Reader", ")", "error", "{", "var", "err", "error", "\n\n", "var", "buf", "[", "1", "]", "byte", "\n", "if", "_", ",", "err", ":=", "io", ".", "ReadFull", "(", "r", ",", ...
// Decode fully populates the target ForwardingMessage from the raw bytes // encoded within the io.Reader. In the case of any decoding errors, an error // will be returned. If the method success, then the new OnionPacket is ready // to be processed by an instance of SphinxNode.
[ "Decode", "fully", "populates", "the", "target", "ForwardingMessage", "from", "the", "raw", "bytes", "encoded", "within", "the", "io", ".", "Reader", ".", "In", "the", "case", "of", "any", "decoding", "errors", "an", "error", "will", "be", "returned", ".", ...
751fb4dd8b72bbaec93889249a6c6ca9f71a5598
https://github.com/lightningnetwork/lightning-onion/blob/751fb4dd8b72bbaec93889249a6c6ca9f71a5598/sphinx.go#L430-L463
11,874
lightningnetwork/lightning-onion
sphinx.go
NewRouter
func NewRouter(nodeKey *btcec.PrivateKey, net *chaincfg.Params, log ReplayLog) *Router { var nodeID [AddressSize]byte copy(nodeID[:], btcutil.Hash160(nodeKey.PubKey().SerializeCompressed())) // Safe to ignore the error here, nodeID is 20 bytes. nodeAddr, _ := btcutil.NewAddressPubKeyHash(nodeID[:], net) return &...
go
func NewRouter(nodeKey *btcec.PrivateKey, net *chaincfg.Params, log ReplayLog) *Router { var nodeID [AddressSize]byte copy(nodeID[:], btcutil.Hash160(nodeKey.PubKey().SerializeCompressed())) // Safe to ignore the error here, nodeID is 20 bytes. nodeAddr, _ := btcutil.NewAddressPubKeyHash(nodeID[:], net) return &...
[ "func", "NewRouter", "(", "nodeKey", "*", "btcec", ".", "PrivateKey", ",", "net", "*", "chaincfg", ".", "Params", ",", "log", "ReplayLog", ")", "*", "Router", "{", "var", "nodeID", "[", "AddressSize", "]", "byte", "\n", "copy", "(", "nodeID", "[", ":",...
// NewRouter creates a new instance of a Sphinx onion Router given the node's // currently advertised onion private key, and the target Bitcoin network.
[ "NewRouter", "creates", "a", "new", "instance", "of", "a", "Sphinx", "onion", "Router", "given", "the", "node", "s", "currently", "advertised", "onion", "private", "key", "and", "the", "target", "Bitcoin", "network", "." ]
751fb4dd8b72bbaec93889249a6c6ca9f71a5598
https://github.com/lightningnetwork/lightning-onion/blob/751fb4dd8b72bbaec93889249a6c6ca9f71a5598/sphinx.go#L536-L556
11,875
lightningnetwork/lightning-onion
sphinx.go
unwrapPacket
func unwrapPacket(onionPkt *OnionPacket, sharedSecret *Hash256, assocData []byte) (*OnionPacket, *HopData, error) { dhKey := onionPkt.EphemeralKey routeInfo := onionPkt.RoutingInfo headerMac := onionPkt.HeaderMAC // Using the derived shared secret, ensure the integrity of the routing // information by checking ...
go
func unwrapPacket(onionPkt *OnionPacket, sharedSecret *Hash256, assocData []byte) (*OnionPacket, *HopData, error) { dhKey := onionPkt.EphemeralKey routeInfo := onionPkt.RoutingInfo headerMac := onionPkt.HeaderMAC // Using the derived shared secret, ensure the integrity of the routing // information by checking ...
[ "func", "unwrapPacket", "(", "onionPkt", "*", "OnionPacket", ",", "sharedSecret", "*", "Hash256", ",", "assocData", "[", "]", "byte", ")", "(", "*", "OnionPacket", ",", "*", "HopData", ",", "error", ")", "{", "dhKey", ":=", "onionPkt", ".", "EphemeralKey",...
// unwrapPacket wraps a layer of the passed onion packet using the specified // shared secret and associated data. The associated data will be used to check // the HMAC at each hop to ensure the same data is passed along with the onion // packet. This function returns the next inner onion packet layer, along with // th...
[ "unwrapPacket", "wraps", "a", "layer", "of", "the", "passed", "onion", "packet", "using", "the", "specified", "shared", "secret", "and", "associated", "data", ".", "The", "associated", "data", "will", "be", "used", "to", "check", "the", "HMAC", "at", "each",...
751fb4dd8b72bbaec93889249a6c6ca9f71a5598
https://github.com/lightningnetwork/lightning-onion/blob/751fb4dd8b72bbaec93889249a6c6ca9f71a5598/sphinx.go#L630-L684
11,876
lightningnetwork/lightning-onion
sphinx.go
processOnionPacket
func processOnionPacket(onionPkt *OnionPacket, sharedSecret *Hash256, assocData []byte, sharedSecretGen sharedSecretGenerator) (*ProcessedPacket, error) { // First, we'll unwrap an initial layer of the onion packet. Typically, // we'll only have a single layer to unwrap, However, if the sender has // additional d...
go
func processOnionPacket(onionPkt *OnionPacket, sharedSecret *Hash256, assocData []byte, sharedSecretGen sharedSecretGenerator) (*ProcessedPacket, error) { // First, we'll unwrap an initial layer of the onion packet. Typically, // we'll only have a single layer to unwrap, However, if the sender has // additional d...
[ "func", "processOnionPacket", "(", "onionPkt", "*", "OnionPacket", ",", "sharedSecret", "*", "Hash256", ",", "assocData", "[", "]", "byte", ",", "sharedSecretGen", "sharedSecretGenerator", ")", "(", "*", "ProcessedPacket", ",", "error", ")", "{", "// First, we'll ...
// processOnionPacket performs the primary key derivation and handling of onion // packets. The processed packets returned from this method should only be used // if the packet was not flagged as a replayed packet.
[ "processOnionPacket", "performs", "the", "primary", "key", "derivation", "and", "handling", "of", "onion", "packets", ".", "The", "processed", "packets", "returned", "from", "this", "method", "should", "only", "be", "used", "if", "the", "packet", "was", "not", ...
751fb4dd8b72bbaec93889249a6c6ca9f71a5598
https://github.com/lightningnetwork/lightning-onion/blob/751fb4dd8b72bbaec93889249a6c6ca9f71a5598/sphinx.go#L689-L723
11,877
lightningnetwork/lightning-onion
sphinx.go
Commit
func (t *Tx) Commit() ([]ProcessedPacket, *ReplaySet, error) { if t.batch.IsCommitted { return t.packets, t.batch.ReplaySet, nil } rs, err := t.router.log.PutBatch(t.batch) return t.packets, rs, err }
go
func (t *Tx) Commit() ([]ProcessedPacket, *ReplaySet, error) { if t.batch.IsCommitted { return t.packets, t.batch.ReplaySet, nil } rs, err := t.router.log.PutBatch(t.batch) return t.packets, rs, err }
[ "func", "(", "t", "*", "Tx", ")", "Commit", "(", ")", "(", "[", "]", "ProcessedPacket", ",", "*", "ReplaySet", ",", "error", ")", "{", "if", "t", ".", "batch", ".", "IsCommitted", "{", "return", "t", ".", "packets", ",", "t", ".", "batch", ".", ...
// Commit writes this transaction's batch of sphinx packets to the replay log, // performing a final check against the log for replays.
[ "Commit", "writes", "this", "transaction", "s", "batch", "of", "sphinx", "packets", "to", "the", "replay", "log", "performing", "a", "final", "check", "against", "the", "log", "for", "replays", "." ]
751fb4dd8b72bbaec93889249a6c6ca9f71a5598
https://github.com/lightningnetwork/lightning-onion/blob/751fb4dd8b72bbaec93889249a6c6ca9f71a5598/sphinx.go#L812-L820
11,878
lightningnetwork/lightning-onion
path.go
IsEmpty
func (o OnionHop) IsEmpty() bool { return o.NodePub.X == nil || o.NodePub.Y == nil }
go
func (o OnionHop) IsEmpty() bool { return o.NodePub.X == nil || o.NodePub.Y == nil }
[ "func", "(", "o", "OnionHop", ")", "IsEmpty", "(", ")", "bool", "{", "return", "o", ".", "NodePub", ".", "X", "==", "nil", "||", "o", ".", "NodePub", ".", "Y", "==", "nil", "\n", "}" ]
// IsEmpty returns true if the hop isn't populated.
[ "IsEmpty", "returns", "true", "if", "the", "hop", "isn", "t", "populated", "." ]
751fb4dd8b72bbaec93889249a6c6ca9f71a5598
https://github.com/lightningnetwork/lightning-onion/blob/751fb4dd8b72bbaec93889249a6c6ca9f71a5598/path.go#L37-L39
11,879
lightningnetwork/lightning-onion
crypto.go
calcMac
func calcMac(key [keyLen]byte, msg []byte) [HMACSize]byte { hmac := hmac.New(sha256.New, key[:]) hmac.Write(msg) h := hmac.Sum(nil) var mac [HMACSize]byte copy(mac[:], h[:HMACSize]) return mac }
go
func calcMac(key [keyLen]byte, msg []byte) [HMACSize]byte { hmac := hmac.New(sha256.New, key[:]) hmac.Write(msg) h := hmac.Sum(nil) var mac [HMACSize]byte copy(mac[:], h[:HMACSize]) return mac }
[ "func", "calcMac", "(", "key", "[", "keyLen", "]", "byte", ",", "msg", "[", "]", "byte", ")", "[", "HMACSize", "]", "byte", "{", "hmac", ":=", "hmac", ".", "New", "(", "sha256", ".", "New", ",", "key", "[", ":", "]", ")", "\n", "hmac", ".", "...
// calcMac calculates HMAC-SHA-256 over the message using the passed secret key // as input to the HMAC.
[ "calcMac", "calculates", "HMAC", "-", "SHA", "-", "256", "over", "the", "message", "using", "the", "passed", "secret", "key", "as", "input", "to", "the", "HMAC", "." ]
751fb4dd8b72bbaec93889249a6c6ca9f71a5598
https://github.com/lightningnetwork/lightning-onion/blob/751fb4dd8b72bbaec93889249a6c6ca9f71a5598/crypto.go#L31-L40
11,880
lightningnetwork/lightning-onion
crypto.go
generateCipherStream
func generateCipherStream(key [keyLen]byte, numBytes uint) []byte { var ( nonce [8]byte ) cipher, err := chacha20.NewCipher(nonce[:], key[:]) if err != nil { panic(err) } output := make([]byte, numBytes) cipher.XORKeyStream(output, output) return output }
go
func generateCipherStream(key [keyLen]byte, numBytes uint) []byte { var ( nonce [8]byte ) cipher, err := chacha20.NewCipher(nonce[:], key[:]) if err != nil { panic(err) } output := make([]byte, numBytes) cipher.XORKeyStream(output, output) return output }
[ "func", "generateCipherStream", "(", "key", "[", "keyLen", "]", "byte", ",", "numBytes", "uint", ")", "[", "]", "byte", "{", "var", "(", "nonce", "[", "8", "]", "byte", "\n", ")", "\n", "cipher", ",", "err", ":=", "chacha20", ".", "NewCipher", "(", ...
// generateCipherStream generates a stream of cryptographic psuedo-random bytes // intended to be used to encrypt a message using a one-time-pad like // construction.
[ "generateCipherStream", "generates", "a", "stream", "of", "cryptographic", "psuedo", "-", "random", "bytes", "intended", "to", "be", "used", "to", "encrypt", "a", "message", "using", "a", "one", "-", "time", "-", "pad", "like", "construction", "." ]
751fb4dd8b72bbaec93889249a6c6ca9f71a5598
https://github.com/lightningnetwork/lightning-onion/blob/751fb4dd8b72bbaec93889249a6c6ca9f71a5598/crypto.go#L73-L85
11,881
lightningnetwork/lightning-onion
crypto.go
generateSharedSecret
func (r *Router) generateSharedSecret(dhKey *btcec.PublicKey) (Hash256, error) { var sharedSecret Hash256 // Ensure that the public key is on our curve. if !btcec.S256().IsOnCurve(dhKey.X, dhKey.Y) { return sharedSecret, ErrInvalidOnionKey } // Compute our shared secret. sharedSecret = generateSharedSecret(dh...
go
func (r *Router) generateSharedSecret(dhKey *btcec.PublicKey) (Hash256, error) { var sharedSecret Hash256 // Ensure that the public key is on our curve. if !btcec.S256().IsOnCurve(dhKey.X, dhKey.Y) { return sharedSecret, ErrInvalidOnionKey } // Compute our shared secret. sharedSecret = generateSharedSecret(dh...
[ "func", "(", "r", "*", "Router", ")", "generateSharedSecret", "(", "dhKey", "*", "btcec", ".", "PublicKey", ")", "(", "Hash256", ",", "error", ")", "{", "var", "sharedSecret", "Hash256", "\n\n", "// Ensure that the public key is on our curve.", "if", "!", "btcec...
// generateSharedSecret generates the shared secret by given ephemeral key.
[ "generateSharedSecret", "generates", "the", "shared", "secret", "by", "given", "ephemeral", "key", "." ]
751fb4dd8b72bbaec93889249a6c6ca9f71a5598
https://github.com/lightningnetwork/lightning-onion/blob/751fb4dd8b72bbaec93889249a6c6ca9f71a5598/crypto.go#L127-L138
11,882
lightningnetwork/lightning-onion
crypto.go
generateSharedSecret
func generateSharedSecret(pub *btcec.PublicKey, priv *btcec.PrivateKey) Hash256 { s := &btcec.PublicKey{} s.X, s.Y = btcec.S256().ScalarMult(pub.X, pub.Y, priv.D.Bytes()) return sha256.Sum256(s.SerializeCompressed()) }
go
func generateSharedSecret(pub *btcec.PublicKey, priv *btcec.PrivateKey) Hash256 { s := &btcec.PublicKey{} s.X, s.Y = btcec.S256().ScalarMult(pub.X, pub.Y, priv.D.Bytes()) return sha256.Sum256(s.SerializeCompressed()) }
[ "func", "generateSharedSecret", "(", "pub", "*", "btcec", ".", "PublicKey", ",", "priv", "*", "btcec", ".", "PrivateKey", ")", "Hash256", "{", "s", ":=", "&", "btcec", ".", "PublicKey", "{", "}", "\n", "s", ".", "X", ",", "s", ".", "Y", "=", "btcec...
// generateSharedSecret generates the shared secret for a particular hop. The // shared secret is generated by taking the group element contained in the // mix-header, and performing an ECDH operation with the node's long term onion // key. We then take the _entire_ point generated by the ECDH operation, // serialize t...
[ "generateSharedSecret", "generates", "the", "shared", "secret", "for", "a", "particular", "hop", ".", "The", "shared", "secret", "is", "generated", "by", "taking", "the", "group", "element", "contained", "in", "the", "mix", "-", "header", "and", "performing", ...
751fb4dd8b72bbaec93889249a6c6ca9f71a5598
https://github.com/lightningnetwork/lightning-onion/blob/751fb4dd8b72bbaec93889249a6c6ca9f71a5598/crypto.go#L146-L151
11,883
lightningnetwork/lightning-onion
crypto.go
DecryptError
func (o *OnionErrorDecrypter) DecryptError(encryptedData []byte) (*btcec.PublicKey, []byte, error) { // Ensure the error message length is as expected. if len(encryptedData) != onionErrorLength { return nil, nil, fmt.Errorf("invalid error length: "+ "expected %v got %v", onionErrorLength, len(encryptedData)) ...
go
func (o *OnionErrorDecrypter) DecryptError(encryptedData []byte) (*btcec.PublicKey, []byte, error) { // Ensure the error message length is as expected. if len(encryptedData) != onionErrorLength { return nil, nil, fmt.Errorf("invalid error length: "+ "expected %v got %v", onionErrorLength, len(encryptedData)) ...
[ "func", "(", "o", "*", "OnionErrorDecrypter", ")", "DecryptError", "(", "encryptedData", "[", "]", "byte", ")", "(", "*", "btcec", ".", "PublicKey", ",", "[", "]", "byte", ",", "error", ")", "{", "// Ensure the error message length is as expected.", "if", "len...
// DecryptError attempts to decrypt the passed encrypted error response. The // onion failure is encrypted in backward manner, starting from the node where // error have occurred. As a result, in order to decrypt the error we need get // all shared secret and apply decryption in the reverse order.
[ "DecryptError", "attempts", "to", "decrypt", "the", "passed", "encrypted", "error", "response", ".", "The", "onion", "failure", "is", "encrypted", "in", "backward", "manner", "starting", "from", "the", "node", "where", "error", "have", "occurred", ".", "As", "...
751fb4dd8b72bbaec93889249a6c6ca9f71a5598
https://github.com/lightningnetwork/lightning-onion/blob/751fb4dd8b72bbaec93889249a6c6ca9f71a5598/crypto.go#L175-L242
11,884
lightningnetwork/lightning-onion
crypto.go
EncryptError
func (o *OnionErrorEncrypter) EncryptError(initial bool, data []byte) []byte { if initial { umKey := generateKey("um", &o.sharedSecret) hash := hmac.New(sha256.New, umKey[:]) hash.Write(data) h := hash.Sum(nil) data = append(h, data...) } return onionEncrypt(&o.sharedSecret, data) }
go
func (o *OnionErrorEncrypter) EncryptError(initial bool, data []byte) []byte { if initial { umKey := generateKey("um", &o.sharedSecret) hash := hmac.New(sha256.New, umKey[:]) hash.Write(data) h := hash.Sum(nil) data = append(h, data...) } return onionEncrypt(&o.sharedSecret, data) }
[ "func", "(", "o", "*", "OnionErrorEncrypter", ")", "EncryptError", "(", "initial", "bool", ",", "data", "[", "]", "byte", ")", "[", "]", "byte", "{", "if", "initial", "{", "umKey", ":=", "generateKey", "(", "\"", "\"", ",", "&", "o", ".", "sharedSecr...
// EncryptError is used to make data obfuscation using the generated shared // secret. // // In context of Lightning Network is either used by the nodes in order to make // initial obfuscation with the creation of the hmac or by the forwarding nodes // for backward failure obfuscation of the onion failure blob. By obfu...
[ "EncryptError", "is", "used", "to", "make", "data", "obfuscation", "using", "the", "generated", "shared", "secret", ".", "In", "context", "of", "Lightning", "Network", "is", "either", "used", "by", "the", "nodes", "in", "order", "to", "make", "initial", "obf...
751fb4dd8b72bbaec93889249a6c6ca9f71a5598
https://github.com/lightningnetwork/lightning-onion/blob/751fb4dd8b72bbaec93889249a6c6ca9f71a5598/crypto.go#L255-L265
11,885
lightningnetwork/lightning-onion
obfuscation.go
NewOnionErrorEncrypter
func NewOnionErrorEncrypter(router *Router, ephemeralKey *btcec.PublicKey) (*OnionErrorEncrypter, error) { sharedSecret, err := router.generateSharedSecret(ephemeralKey) if err != nil { return nil, err } return &OnionErrorEncrypter{ sharedSecret: sharedSecret, }, nil }
go
func NewOnionErrorEncrypter(router *Router, ephemeralKey *btcec.PublicKey) (*OnionErrorEncrypter, error) { sharedSecret, err := router.generateSharedSecret(ephemeralKey) if err != nil { return nil, err } return &OnionErrorEncrypter{ sharedSecret: sharedSecret, }, nil }
[ "func", "NewOnionErrorEncrypter", "(", "router", "*", "Router", ",", "ephemeralKey", "*", "btcec", ".", "PublicKey", ")", "(", "*", "OnionErrorEncrypter", ",", "error", ")", "{", "sharedSecret", ",", "err", ":=", "router", ".", "generateSharedSecret", "(", "ep...
// NewOnionErrorEncrypter creates new instance of the onion encrypter backed by // the passed router, with encryption to be doing using the passed // ephemeralKey.
[ "NewOnionErrorEncrypter", "creates", "new", "instance", "of", "the", "onion", "encrypter", "backed", "by", "the", "passed", "router", "with", "encryption", "to", "be", "doing", "using", "the", "passed", "ephemeralKey", "." ]
751fb4dd8b72bbaec93889249a6c6ca9f71a5598
https://github.com/lightningnetwork/lightning-onion/blob/751fb4dd8b72bbaec93889249a6c6ca9f71a5598/obfuscation.go#L18-L29
11,886
lightningnetwork/lightning-onion
obfuscation.go
Encode
func (o *OnionErrorEncrypter) Encode(w io.Writer) error { _, err := w.Write(o.sharedSecret[:]) return err }
go
func (o *OnionErrorEncrypter) Encode(w io.Writer) error { _, err := w.Write(o.sharedSecret[:]) return err }
[ "func", "(", "o", "*", "OnionErrorEncrypter", ")", "Encode", "(", "w", "io", ".", "Writer", ")", "error", "{", "_", ",", "err", ":=", "w", ".", "Write", "(", "o", ".", "sharedSecret", "[", ":", "]", ")", "\n", "return", "err", "\n", "}" ]
// Encode writes the encrypter's shared secret to the provided io.Writer.
[ "Encode", "writes", "the", "encrypter", "s", "shared", "secret", "to", "the", "provided", "io", ".", "Writer", "." ]
751fb4dd8b72bbaec93889249a6c6ca9f71a5598
https://github.com/lightningnetwork/lightning-onion/blob/751fb4dd8b72bbaec93889249a6c6ca9f71a5598/obfuscation.go#L32-L35
11,887
lightningnetwork/lightning-onion
obfuscation.go
Decode
func (o *OnionErrorEncrypter) Decode(r io.Reader) error { _, err := io.ReadFull(r, o.sharedSecret[:]) return err }
go
func (o *OnionErrorEncrypter) Decode(r io.Reader) error { _, err := io.ReadFull(r, o.sharedSecret[:]) return err }
[ "func", "(", "o", "*", "OnionErrorEncrypter", ")", "Decode", "(", "r", "io", ".", "Reader", ")", "error", "{", "_", ",", "err", ":=", "io", ".", "ReadFull", "(", "r", ",", "o", ".", "sharedSecret", "[", ":", "]", ")", "\n", "return", "err", "\n",...
// Decode restores the encrypter's share secret from the provided io.Reader.
[ "Decode", "restores", "the", "encrypter", "s", "share", "secret", "from", "the", "provided", "io", ".", "Reader", "." ]
751fb4dd8b72bbaec93889249a6c6ca9f71a5598
https://github.com/lightningnetwork/lightning-onion/blob/751fb4dd8b72bbaec93889249a6c6ca9f71a5598/obfuscation.go#L38-L41
11,888
lightningnetwork/lightning-onion
obfuscation.go
Decode
func (c *Circuit) Decode(r io.Reader) error { var keyLength [1]byte if _, err := r.Read(keyLength[:]); err != nil { return err } sessionKeyData := make([]byte, uint8(keyLength[0])) if _, err := r.Read(sessionKeyData[:]); err != nil { return err } c.SessionKey, _ = btcec.PrivKeyFromBytes(btcec.S256(), sessi...
go
func (c *Circuit) Decode(r io.Reader) error { var keyLength [1]byte if _, err := r.Read(keyLength[:]); err != nil { return err } sessionKeyData := make([]byte, uint8(keyLength[0])) if _, err := r.Read(sessionKeyData[:]); err != nil { return err } c.SessionKey, _ = btcec.PrivKeyFromBytes(btcec.S256(), sessi...
[ "func", "(", "c", "*", "Circuit", ")", "Decode", "(", "r", "io", ".", "Reader", ")", "error", "{", "var", "keyLength", "[", "1", "]", "byte", "\n", "if", "_", ",", "err", ":=", "r", ".", "Read", "(", "keyLength", "[", ":", "]", ")", ";", "err...
// Decode initializes the circuit from the byte stream.
[ "Decode", "initializes", "the", "circuit", "from", "the", "byte", "stream", "." ]
751fb4dd8b72bbaec93889249a6c6ca9f71a5598
https://github.com/lightningnetwork/lightning-onion/blob/751fb4dd8b72bbaec93889249a6c6ca9f71a5598/obfuscation.go#L54-L86
11,889
lightningnetwork/lightning-onion
obfuscation.go
Encode
func (c *Circuit) Encode(w io.Writer) error { var keyLength [1]byte keyLength[0] = uint8(len(c.SessionKey.Serialize())) if _, err := w.Write(keyLength[:]); err != nil { return err } if _, err := w.Write(c.SessionKey.Serialize()); err != nil { return err } var pathLength [1]byte pathLength[0] = uint8(len(c...
go
func (c *Circuit) Encode(w io.Writer) error { var keyLength [1]byte keyLength[0] = uint8(len(c.SessionKey.Serialize())) if _, err := w.Write(keyLength[:]); err != nil { return err } if _, err := w.Write(c.SessionKey.Serialize()); err != nil { return err } var pathLength [1]byte pathLength[0] = uint8(len(c...
[ "func", "(", "c", "*", "Circuit", ")", "Encode", "(", "w", "io", ".", "Writer", ")", "error", "{", "var", "keyLength", "[", "1", "]", "byte", "\n", "keyLength", "[", "0", "]", "=", "uint8", "(", "len", "(", "c", ".", "SessionKey", ".", "Serialize...
// Encode writes converted circuit in the byte stream.
[ "Encode", "writes", "converted", "circuit", "in", "the", "byte", "stream", "." ]
751fb4dd8b72bbaec93889249a6c6ca9f71a5598
https://github.com/lightningnetwork/lightning-onion/blob/751fb4dd8b72bbaec93889249a6c6ca9f71a5598/obfuscation.go#L89-L113
11,890
lightningnetwork/lightning-onion
replay_set.go
Contains
func (rs *ReplaySet) Contains(idx uint16) bool { _, ok := rs.replays[idx] return ok }
go
func (rs *ReplaySet) Contains(idx uint16) bool { _, ok := rs.replays[idx] return ok }
[ "func", "(", "rs", "*", "ReplaySet", ")", "Contains", "(", "idx", "uint16", ")", "bool", "{", "_", ",", "ok", ":=", "rs", ".", "replays", "[", "idx", "]", "\n", "return", "ok", "\n", "}" ]
// Contains queries the contents of the replay set for membership of a // particular index.
[ "Contains", "queries", "the", "contents", "of", "the", "replay", "set", "for", "membership", "of", "a", "particular", "index", "." ]
751fb4dd8b72bbaec93889249a6c6ca9f71a5598
https://github.com/lightningnetwork/lightning-onion/blob/751fb4dd8b72bbaec93889249a6c6ca9f71a5598/replay_set.go#L35-L38
11,891
lightningnetwork/lightning-onion
replay_set.go
Merge
func (rs *ReplaySet) Merge(rs2 *ReplaySet) { for seqNum := range rs2.replays { rs.Add(seqNum) } }
go
func (rs *ReplaySet) Merge(rs2 *ReplaySet) { for seqNum := range rs2.replays { rs.Add(seqNum) } }
[ "func", "(", "rs", "*", "ReplaySet", ")", "Merge", "(", "rs2", "*", "ReplaySet", ")", "{", "for", "seqNum", ":=", "range", "rs2", ".", "replays", "{", "rs", ".", "Add", "(", "seqNum", ")", "\n", "}", "\n", "}" ]
// Merge adds the contents of the provided replay set to the receiver's set.
[ "Merge", "adds", "the", "contents", "of", "the", "provided", "replay", "set", "to", "the", "receiver", "s", "set", "." ]
751fb4dd8b72bbaec93889249a6c6ca9f71a5598
https://github.com/lightningnetwork/lightning-onion/blob/751fb4dd8b72bbaec93889249a6c6ca9f71a5598/replay_set.go#L41-L45
11,892
lightningnetwork/lightning-onion
replay_set.go
Encode
func (rs *ReplaySet) Encode(w io.Writer) error { for seqNum := range rs.replays { err := binary.Write(w, binary.BigEndian, seqNum) if err != nil { return err } } return nil }
go
func (rs *ReplaySet) Encode(w io.Writer) error { for seqNum := range rs.replays { err := binary.Write(w, binary.BigEndian, seqNum) if err != nil { return err } } return nil }
[ "func", "(", "rs", "*", "ReplaySet", ")", "Encode", "(", "w", "io", ".", "Writer", ")", "error", "{", "for", "seqNum", ":=", "range", "rs", ".", "replays", "{", "err", ":=", "binary", ".", "Write", "(", "w", ",", "binary", ".", "BigEndian", ",", ...
// Encode serializes the replay set into an io.Writer suitable for storage. The // replay set can be recovered using Decode.
[ "Encode", "serializes", "the", "replay", "set", "into", "an", "io", ".", "Writer", "suitable", "for", "storage", ".", "The", "replay", "set", "can", "be", "recovered", "using", "Decode", "." ]
751fb4dd8b72bbaec93889249a6c6ca9f71a5598
https://github.com/lightningnetwork/lightning-onion/blob/751fb4dd8b72bbaec93889249a6c6ca9f71a5598/replay_set.go#L49-L58
11,893
lightningnetwork/lightning-onion
replay_set.go
Decode
func (rs *ReplaySet) Decode(r io.Reader) error { for { // seqNum provides to buffer to read the next uint16 index. var seqNum uint16 err := binary.Read(r, binary.BigEndian, &seqNum) switch err { case nil: // Successful read, proceed. case io.EOF: return nil default: // Can return ErrShortBuffer...
go
func (rs *ReplaySet) Decode(r io.Reader) error { for { // seqNum provides to buffer to read the next uint16 index. var seqNum uint16 err := binary.Read(r, binary.BigEndian, &seqNum) switch err { case nil: // Successful read, proceed. case io.EOF: return nil default: // Can return ErrShortBuffer...
[ "func", "(", "rs", "*", "ReplaySet", ")", "Decode", "(", "r", "io", ".", "Reader", ")", "error", "{", "for", "{", "// seqNum provides to buffer to read the next uint16 index.", "var", "seqNum", "uint16", "\n\n", "err", ":=", "binary", ".", "Read", "(", "r", ...
// Decode reconstructs a replay set given a io.Reader. The byte // slice is assumed to be even in length, otherwise resulting in failure.
[ "Decode", "reconstructs", "a", "replay", "set", "given", "a", "io", ".", "Reader", ".", "The", "byte", "slice", "is", "assumed", "to", "be", "even", "in", "length", "otherwise", "resulting", "in", "failure", "." ]
751fb4dd8b72bbaec93889249a6c6ca9f71a5598
https://github.com/lightningnetwork/lightning-onion/blob/751fb4dd8b72bbaec93889249a6c6ca9f71a5598/replay_set.go#L62-L81
11,894
evalphobia/logrus_sentry
sentry_setter.go
SetHttpContext
func (hook *SentryHook) SetHttpContext(h *raven.Http) { hook.client.SetHttpContext(h) }
go
func (hook *SentryHook) SetHttpContext(h *raven.Http) { hook.client.SetHttpContext(h) }
[ "func", "(", "hook", "*", "SentryHook", ")", "SetHttpContext", "(", "h", "*", "raven", ".", "Http", ")", "{", "hook", ".", "client", ".", "SetHttpContext", "(", "h", ")", "\n", "}" ]
// SetHttpContext sets http client.
[ "SetHttpContext", "sets", "http", "client", "." ]
ab0fa2ee9517a8e8c1de1c07e492e8164f852529
https://github.com/evalphobia/logrus_sentry/blob/ab0fa2ee9517a8e8c1de1c07e492e8164f852529/sentry_setter.go#L18-L20
11,895
evalphobia/logrus_sentry
sentry_setter.go
SetIgnoreErrors
func (hook *SentryHook) SetIgnoreErrors(errs ...string) error { return hook.client.SetIgnoreErrors(errs) }
go
func (hook *SentryHook) SetIgnoreErrors(errs ...string) error { return hook.client.SetIgnoreErrors(errs) }
[ "func", "(", "hook", "*", "SentryHook", ")", "SetIgnoreErrors", "(", "errs", "...", "string", ")", "error", "{", "return", "hook", ".", "client", ".", "SetIgnoreErrors", "(", "errs", ")", "\n", "}" ]
// SetIgnoreErrors sets ignoreErrorsRegexp.
[ "SetIgnoreErrors", "sets", "ignoreErrorsRegexp", "." ]
ab0fa2ee9517a8e8c1de1c07e492e8164f852529
https://github.com/evalphobia/logrus_sentry/blob/ab0fa2ee9517a8e8c1de1c07e492e8164f852529/sentry_setter.go#L23-L25
11,896
evalphobia/logrus_sentry
sentry_setter.go
SetSampleRate
func (hook *SentryHook) SetSampleRate(rate float32) error { return hook.client.SetSampleRate(rate) }
go
func (hook *SentryHook) SetSampleRate(rate float32) error { return hook.client.SetSampleRate(rate) }
[ "func", "(", "hook", "*", "SentryHook", ")", "SetSampleRate", "(", "rate", "float32", ")", "error", "{", "return", "hook", ".", "client", ".", "SetSampleRate", "(", "rate", ")", "\n", "}" ]
// SetSampleRate sets sampling rate.
[ "SetSampleRate", "sets", "sampling", "rate", "." ]
ab0fa2ee9517a8e8c1de1c07e492e8164f852529
https://github.com/evalphobia/logrus_sentry/blob/ab0fa2ee9517a8e8c1de1c07e492e8164f852529/sentry_setter.go#L38-L40
11,897
evalphobia/logrus_sentry
sentry_setter.go
SetTagsContext
func (hook *SentryHook) SetTagsContext(t map[string]string) { hook.client.SetTagsContext(t) }
go
func (hook *SentryHook) SetTagsContext(t map[string]string) { hook.client.SetTagsContext(t) }
[ "func", "(", "hook", "*", "SentryHook", ")", "SetTagsContext", "(", "t", "map", "[", "string", "]", "string", ")", "{", "hook", ".", "client", ".", "SetTagsContext", "(", "t", ")", "\n", "}" ]
// SetTagsContext sets tags.
[ "SetTagsContext", "sets", "tags", "." ]
ab0fa2ee9517a8e8c1de1c07e492e8164f852529
https://github.com/evalphobia/logrus_sentry/blob/ab0fa2ee9517a8e8c1de1c07e492e8164f852529/sentry_setter.go#L43-L45
11,898
evalphobia/logrus_sentry
sentry_setter.go
SetUserContext
func (hook *SentryHook) SetUserContext(u *raven.User) { hook.client.SetUserContext(u) }
go
func (hook *SentryHook) SetUserContext(u *raven.User) { hook.client.SetUserContext(u) }
[ "func", "(", "hook", "*", "SentryHook", ")", "SetUserContext", "(", "u", "*", "raven", ".", "User", ")", "{", "hook", ".", "client", ".", "SetUserContext", "(", "u", ")", "\n", "}" ]
// SetUserContext sets user.
[ "SetUserContext", "sets", "user", "." ]
ab0fa2ee9517a8e8c1de1c07e492e8164f852529
https://github.com/evalphobia/logrus_sentry/blob/ab0fa2ee9517a8e8c1de1c07e492e8164f852529/sentry_setter.go#L48-L50
11,899
evalphobia/logrus_sentry
utils.go
xtob
func xtob(x string) (byte, bool) { b1 := xvalues[x[0]] b2 := xvalues[x[1]] return (b1 << 4) | b2, b1 != 255 && b2 != 255 }
go
func xtob(x string) (byte, bool) { b1 := xvalues[x[0]] b2 := xvalues[x[1]] return (b1 << 4) | b2, b1 != 255 && b2 != 255 }
[ "func", "xtob", "(", "x", "string", ")", "(", "byte", ",", "bool", ")", "{", "b1", ":=", "xvalues", "[", "x", "[", "0", "]", "]", "\n", "b2", ":=", "xvalues", "[", "x", "[", "1", "]", "]", "\n", "return", "(", "b1", "<<", "4", ")", "|", "...
// xtob converts the the first two hex bytes of x into a byte.
[ "xtob", "converts", "the", "the", "first", "two", "hex", "bytes", "of", "x", "into", "a", "byte", "." ]
ab0fa2ee9517a8e8c1de1c07e492e8164f852529
https://github.com/evalphobia/logrus_sentry/blob/ab0fa2ee9517a8e8c1de1c07e492e8164f852529/utils.go#L131-L135