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
144,200
libopenstorage/openstorage
pkg/storageops/gce/gce.go
IsDevMode
func IsDevMode() bool { var i = new(instance) err := gceInfoFromEnv(i) return err == nil }
go
func IsDevMode() bool { var i = new(instance) err := gceInfoFromEnv(i) return err == nil }
[ "func", "IsDevMode", "(", ")", "bool", "{", "var", "i", "=", "new", "(", "instance", ")", "\n", "err", ":=", "gceInfoFromEnv", "(", "i", ")", "\n", "return", "err", "==", "nil", "\n", "}" ]
// IsDevMode checks if the pkg is invoked in developer mode where GCE credentials // are set as env variables
[ "IsDevMode", "checks", "if", "the", "pkg", "is", "invoked", "in", "developer", "mode", "where", "GCE", "credentials", "are", "set", "as", "env", "variables" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/storageops/gce/gce.go#L50-L54
144,201
libopenstorage/openstorage
pkg/storageops/gce/gce.go
NewClient
func NewClient() (storageops.Ops, error) { var i = new(instance) var err error if metadata.OnGCE() { err = gceInfo(i) } else if ok := IsDevMode(); ok { err = gceInfoFromEnv(i) } else { return nil, fmt.Errorf("instance is not running on GCE") } if err != nil { return nil, fmt.Errorf("error fetching instance info. Err: %v", err) } c, err := google.DefaultClient(context.Background(), compute.ComputeScope) if err != nil { return nil, fmt.Errorf("failed to authenticate with google api. Err: %v", err) } service, err := compute.New(c) if err != nil { return nil, fmt.Errorf("unable to create Compute service: %v", err) } return &gceOps{ inst: i, service: service, }, nil }
go
func NewClient() (storageops.Ops, error) { var i = new(instance) var err error if metadata.OnGCE() { err = gceInfo(i) } else if ok := IsDevMode(); ok { err = gceInfoFromEnv(i) } else { return nil, fmt.Errorf("instance is not running on GCE") } if err != nil { return nil, fmt.Errorf("error fetching instance info. Err: %v", err) } c, err := google.DefaultClient(context.Background(), compute.ComputeScope) if err != nil { return nil, fmt.Errorf("failed to authenticate with google api. Err: %v", err) } service, err := compute.New(c) if err != nil { return nil, fmt.Errorf("unable to create Compute service: %v", err) } return &gceOps{ inst: i, service: service, }, nil }
[ "func", "NewClient", "(", ")", "(", "storageops", ".", "Ops", ",", "error", ")", "{", "var", "i", "=", "new", "(", "instance", ")", "\n", "var", "err", "error", "\n", "if", "metadata", ".", "OnGCE", "(", ")", "{", "err", "=", "gceInfo", "(", "i", ")", "\n", "}", "else", "if", "ok", ":=", "IsDevMode", "(", ")", ";", "ok", "{", "err", "=", "gceInfoFromEnv", "(", "i", ")", "\n", "}", "else", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "c", ",", "err", ":=", "google", ".", "DefaultClient", "(", "context", ".", "Background", "(", ")", ",", "compute", ".", "ComputeScope", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "service", ",", "err", ":=", "compute", ".", "New", "(", "c", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "return", "&", "gceOps", "{", "inst", ":", "i", ",", "service", ":", "service", ",", "}", ",", "nil", "\n", "}" ]
// NewClient creates a new GCE operations client
[ "NewClient", "creates", "a", "new", "GCE", "operations", "client" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/storageops/gce/gce.go#L57-L86
144,202
libopenstorage/openstorage
pkg/storageops/gce/gce.go
gceInfo
func gceInfo(inst *instance) error { var err error inst.zone, err = metadata.Zone() if err != nil { return err } inst.name, err = metadata.InstanceName() if err != nil { return err } inst.hostname, err = metadata.Hostname() if err != nil { return err } inst.project, err = metadata.ProjectID() if err != nil { return err } return nil }
go
func gceInfo(inst *instance) error { var err error inst.zone, err = metadata.Zone() if err != nil { return err } inst.name, err = metadata.InstanceName() if err != nil { return err } inst.hostname, err = metadata.Hostname() if err != nil { return err } inst.project, err = metadata.ProjectID() if err != nil { return err } return nil }
[ "func", "gceInfo", "(", "inst", "*", "instance", ")", "error", "{", "var", "err", "error", "\n", "inst", ".", "zone", ",", "err", "=", "metadata", ".", "Zone", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "inst", ".", "name", ",", "err", "=", "metadata", ".", "InstanceName", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "inst", ".", "hostname", ",", "err", "=", "metadata", ".", "Hostname", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "inst", ".", "project", ",", "err", "=", "metadata", ".", "ProjectID", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// gceInfo fetches the GCE instance metadata from the metadata server
[ "gceInfo", "fetches", "the", "GCE", "instance", "metadata", "from", "the", "metadata", "server" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/storageops/gce/gce.go#L531-L554
144,203
libopenstorage/openstorage
pkg/storageops/gce/gce.go
waitForDetach
func (s *gceOps) waitForDetach( diskURL string, timeout time.Duration, ) error { _, err := task.DoRetryWithTimeout( func() (interface{}, bool, error) { inst, err := s.describeinstance() if err != nil { return nil, true, err } for _, d := range inst.Disks { if d.Source == diskURL { return nil, true, fmt.Errorf("disk: %s is still attached to instance: %s", diskURL, s.inst.name) } } return nil, false, nil }, storageops.ProviderOpsTimeout, storageops.ProviderOpsRetryInterval) return err }
go
func (s *gceOps) waitForDetach( diskURL string, timeout time.Duration, ) error { _, err := task.DoRetryWithTimeout( func() (interface{}, bool, error) { inst, err := s.describeinstance() if err != nil { return nil, true, err } for _, d := range inst.Disks { if d.Source == diskURL { return nil, true, fmt.Errorf("disk: %s is still attached to instance: %s", diskURL, s.inst.name) } } return nil, false, nil }, storageops.ProviderOpsTimeout, storageops.ProviderOpsRetryInterval) return err }
[ "func", "(", "s", "*", "gceOps", ")", "waitForDetach", "(", "diskURL", "string", ",", "timeout", "time", ".", "Duration", ",", ")", "error", "{", "_", ",", "err", ":=", "task", ".", "DoRetryWithTimeout", "(", "func", "(", ")", "(", "interface", "{", "}", ",", "bool", ",", "error", ")", "{", "inst", ",", "err", ":=", "s", ".", "describeinstance", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "true", ",", "err", "\n", "}", "\n\n", "for", "_", ",", "d", ":=", "range", "inst", ".", "Disks", "{", "if", "d", ".", "Source", "==", "diskURL", "{", "return", "nil", ",", "true", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "diskURL", ",", "s", ".", "inst", ".", "name", ")", "\n", "}", "\n", "}", "\n\n", "return", "nil", ",", "false", ",", "nil", "\n\n", "}", ",", "storageops", ".", "ProviderOpsTimeout", ",", "storageops", ".", "ProviderOpsRetryInterval", ")", "\n\n", "return", "err", "\n", "}" ]
// waitForDetach checks if given disk is detached from the local instance
[ "waitForDetach", "checks", "if", "given", "disk", "is", "detached", "from", "the", "local", "instance" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/storageops/gce/gce.go#L586-L613
144,204
libopenstorage/openstorage
pkg/storageops/gce/gce.go
waitForAttach
func (s *gceOps) waitForAttach( disk *compute.Disk, timeout time.Duration, ) (string, error) { devicePath, err := task.DoRetryWithTimeout( func() (interface{}, bool, error) { devicePath, err := s.DevicePath(disk.Name) if se, ok := err.(*storageops.StorageError); ok && se.Code == storageops.ErrVolAttachedOnRemoteNode { return "", false, err } else if err != nil { return "", true, err } return devicePath, false, nil }, storageops.ProviderOpsTimeout, storageops.ProviderOpsRetryInterval) if err != nil { return "", err } return devicePath.(string), nil }
go
func (s *gceOps) waitForAttach( disk *compute.Disk, timeout time.Duration, ) (string, error) { devicePath, err := task.DoRetryWithTimeout( func() (interface{}, bool, error) { devicePath, err := s.DevicePath(disk.Name) if se, ok := err.(*storageops.StorageError); ok && se.Code == storageops.ErrVolAttachedOnRemoteNode { return "", false, err } else if err != nil { return "", true, err } return devicePath, false, nil }, storageops.ProviderOpsTimeout, storageops.ProviderOpsRetryInterval) if err != nil { return "", err } return devicePath.(string), nil }
[ "func", "(", "s", "*", "gceOps", ")", "waitForAttach", "(", "disk", "*", "compute", ".", "Disk", ",", "timeout", "time", ".", "Duration", ",", ")", "(", "string", ",", "error", ")", "{", "devicePath", ",", "err", ":=", "task", ".", "DoRetryWithTimeout", "(", "func", "(", ")", "(", "interface", "{", "}", ",", "bool", ",", "error", ")", "{", "devicePath", ",", "err", ":=", "s", ".", "DevicePath", "(", "disk", ".", "Name", ")", "\n", "if", "se", ",", "ok", ":=", "err", ".", "(", "*", "storageops", ".", "StorageError", ")", ";", "ok", "&&", "se", ".", "Code", "==", "storageops", ".", "ErrVolAttachedOnRemoteNode", "{", "return", "\"", "\"", ",", "false", ",", "err", "\n", "}", "else", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "true", ",", "err", "\n", "}", "\n\n", "return", "devicePath", ",", "false", ",", "nil", "\n", "}", ",", "storageops", ".", "ProviderOpsTimeout", ",", "storageops", ".", "ProviderOpsRetryInterval", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n\n", "return", "devicePath", ".", "(", "string", ")", ",", "nil", "\n", "}" ]
// waitForAttach checks if given disk is attached to the local instance
[ "waitForAttach", "checks", "if", "given", "disk", "is", "attached", "to", "the", "local", "instance" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/storageops/gce/gce.go#L616-L639
144,205
libopenstorage/openstorage
pkg/grpcserver/grpcserver.go
New
func New(config *GrpcServerConfig) (*GrpcServer, error) { if nil == config { return nil, fmt.Errorf("Configuration must be provided") } if len(config.Name) == 0 { return nil, fmt.Errorf("Name of server must be provided") } if len(config.Address) == 0 { return nil, fmt.Errorf("Address must be provided") } if len(config.Net) == 0 { return nil, fmt.Errorf("Net must be provided") } l, err := net.Listen(config.Net, config.Address) if err != nil { return nil, fmt.Errorf("Unable to setup server: %s", err.Error()) } return &GrpcServer{ name: config.Name, listener: l, }, nil }
go
func New(config *GrpcServerConfig) (*GrpcServer, error) { if nil == config { return nil, fmt.Errorf("Configuration must be provided") } if len(config.Name) == 0 { return nil, fmt.Errorf("Name of server must be provided") } if len(config.Address) == 0 { return nil, fmt.Errorf("Address must be provided") } if len(config.Net) == 0 { return nil, fmt.Errorf("Net must be provided") } l, err := net.Listen(config.Net, config.Address) if err != nil { return nil, fmt.Errorf("Unable to setup server: %s", err.Error()) } return &GrpcServer{ name: config.Name, listener: l, }, nil }
[ "func", "New", "(", "config", "*", "GrpcServerConfig", ")", "(", "*", "GrpcServer", ",", "error", ")", "{", "if", "nil", "==", "config", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "len", "(", "config", ".", "Name", ")", "==", "0", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "len", "(", "config", ".", "Address", ")", "==", "0", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "len", "(", "config", ".", "Net", ")", "==", "0", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "l", ",", "err", ":=", "net", ".", "Listen", "(", "config", ".", "Net", ",", "config", ".", "Address", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ".", "Error", "(", ")", ")", "\n", "}", "\n\n", "return", "&", "GrpcServer", "{", "name", ":", "config", ".", "Name", ",", "listener", ":", "l", ",", "}", ",", "nil", "\n", "}" ]
// New creates a gRPC server on the specified port and transport.
[ "New", "creates", "a", "gRPC", "server", "on", "the", "specified", "port", "and", "transport", "." ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/grpcserver/grpcserver.go#L48-L71
144,206
libopenstorage/openstorage
pkg/grpcserver/grpcserver.go
Start
func (s *GrpcServer) Start(register func(grpcServer *grpc.Server)) error { s.lock.Lock() defer s.lock.Unlock() if s.running { return fmt.Errorf("Server already running") } s.server = grpc.NewServer() register(s.server) // Start listening for requests s.startGrpcService() return nil }
go
func (s *GrpcServer) Start(register func(grpcServer *grpc.Server)) error { s.lock.Lock() defer s.lock.Unlock() if s.running { return fmt.Errorf("Server already running") } s.server = grpc.NewServer() register(s.server) // Start listening for requests s.startGrpcService() return nil }
[ "func", "(", "s", "*", "GrpcServer", ")", "Start", "(", "register", "func", "(", "grpcServer", "*", "grpc", ".", "Server", ")", ")", "error", "{", "s", ".", "lock", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "lock", ".", "Unlock", "(", ")", "\n\n", "if", "s", ".", "running", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "s", ".", "server", "=", "grpc", ".", "NewServer", "(", ")", "\n", "register", "(", "s", ".", "server", ")", "\n\n", "// Start listening for requests", "s", ".", "startGrpcService", "(", ")", "\n", "return", "nil", "\n", "}" ]
// Start is used to start the server. // It will return an error if the server is already runnig.
[ "Start", "is", "used", "to", "start", "the", "server", ".", "It", "will", "return", "an", "error", "if", "the", "server", "is", "already", "runnig", "." ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/grpcserver/grpcserver.go#L75-L89
144,207
libopenstorage/openstorage
pkg/grpcserver/grpcserver.go
StartWithServer
func (s *GrpcServer) StartWithServer(server func() *grpc.Server) error { s.lock.Lock() defer s.lock.Unlock() if server == nil { return fmt.Errorf("Server function has not been defined") } if s.running { return fmt.Errorf("Server already running") } s.server = server() // Start listening for requests s.startGrpcService() return nil }
go
func (s *GrpcServer) StartWithServer(server func() *grpc.Server) error { s.lock.Lock() defer s.lock.Unlock() if server == nil { return fmt.Errorf("Server function has not been defined") } if s.running { return fmt.Errorf("Server already running") } s.server = server() // Start listening for requests s.startGrpcService() return nil }
[ "func", "(", "s", "*", "GrpcServer", ")", "StartWithServer", "(", "server", "func", "(", ")", "*", "grpc", ".", "Server", ")", "error", "{", "s", ".", "lock", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "lock", ".", "Unlock", "(", ")", "\n\n", "if", "server", "==", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "if", "s", ".", "running", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "s", ".", "server", "=", "server", "(", ")", "\n\n", "// Start listening for requests", "s", ".", "startGrpcService", "(", ")", "\n", "return", "nil", "\n", "}" ]
// StartWithServer is used to start the server. // It will return an error if the server is already runnig.
[ "StartWithServer", "is", "used", "to", "start", "the", "server", ".", "It", "will", "return", "an", "error", "if", "the", "server", "is", "already", "runnig", "." ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/grpcserver/grpcserver.go#L93-L110
144,208
libopenstorage/openstorage
pkg/grpcserver/grpcserver.go
startGrpcService
func (s *GrpcServer) startGrpcService() { // Start listening for requests reflection.Register(s.server) logrus.Infof("%s gRPC Server ready on %s", s.name, s.Address()) waitForServer := make(chan bool) s.goServe(waitForServer) <-waitForServer s.running = true }
go
func (s *GrpcServer) startGrpcService() { // Start listening for requests reflection.Register(s.server) logrus.Infof("%s gRPC Server ready on %s", s.name, s.Address()) waitForServer := make(chan bool) s.goServe(waitForServer) <-waitForServer s.running = true }
[ "func", "(", "s", "*", "GrpcServer", ")", "startGrpcService", "(", ")", "{", "// Start listening for requests", "reflection", ".", "Register", "(", "s", ".", "server", ")", "\n", "logrus", ".", "Infof", "(", "\"", "\"", ",", "s", ".", "name", ",", "s", ".", "Address", "(", ")", ")", "\n", "waitForServer", ":=", "make", "(", "chan", "bool", ")", "\n", "s", ".", "goServe", "(", "waitForServer", ")", "\n", "<-", "waitForServer", "\n", "s", ".", "running", "=", "true", "\n", "}" ]
// Lock must have been taken
[ "Lock", "must", "have", "been", "taken" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/grpcserver/grpcserver.go#L113-L121
144,209
libopenstorage/openstorage
pkg/grpcserver/grpcserver.go
Stop
func (s *GrpcServer) Stop() { s.lock.Lock() defer s.lock.Unlock() if !s.running { return } s.server.Stop() s.wg.Wait() s.running = false }
go
func (s *GrpcServer) Stop() { s.lock.Lock() defer s.lock.Unlock() if !s.running { return } s.server.Stop() s.wg.Wait() s.running = false }
[ "func", "(", "s", "*", "GrpcServer", ")", "Stop", "(", ")", "{", "s", ".", "lock", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "lock", ".", "Unlock", "(", ")", "\n\n", "if", "!", "s", ".", "running", "{", "return", "\n", "}", "\n\n", "s", ".", "server", ".", "Stop", "(", ")", "\n", "s", ".", "wg", ".", "Wait", "(", ")", "\n", "s", ".", "running", "=", "false", "\n", "}" ]
// Stop is used to stop the gRPC server. // It can be called multiple times. It does nothing if the server // has already been stopped.
[ "Stop", "is", "used", "to", "stop", "the", "gRPC", "server", ".", "It", "can", "be", "called", "multiple", "times", ".", "It", "does", "nothing", "if", "the", "server", "has", "already", "been", "stopped", "." ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/grpcserver/grpcserver.go#L126-L137
144,210
libopenstorage/openstorage
pkg/grpcserver/grpcserver.go
IsRunning
func (s *GrpcServer) IsRunning() bool { s.lock.Lock() defer s.lock.Unlock() return s.running }
go
func (s *GrpcServer) IsRunning() bool { s.lock.Lock() defer s.lock.Unlock() return s.running }
[ "func", "(", "s", "*", "GrpcServer", ")", "IsRunning", "(", ")", "bool", "{", "s", ".", "lock", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "lock", ".", "Unlock", "(", ")", "\n\n", "return", "s", ".", "running", "\n", "}" ]
// IsRunning returns true if the server is currently running
[ "IsRunning", "returns", "true", "if", "the", "server", "is", "currently", "running" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/grpcserver/grpcserver.go#L146-L151
144,211
libopenstorage/openstorage
osdconfig/api.go
GetClusterConf
func (manager *configManager) GetClusterConf() (*ClusterConfig, error) { // get json from kvdb and unmarshal into config kvPair, err := manager.kv.Get(filepath.Join(baseKey, clusterKey)) if err != nil { return nil, err } config := new(ClusterConfig) if err := json.Unmarshal(kvPair.Value, config); err != nil { return nil, err } return config, nil }
go
func (manager *configManager) GetClusterConf() (*ClusterConfig, error) { // get json from kvdb and unmarshal into config kvPair, err := manager.kv.Get(filepath.Join(baseKey, clusterKey)) if err != nil { return nil, err } config := new(ClusterConfig) if err := json.Unmarshal(kvPair.Value, config); err != nil { return nil, err } return config, nil }
[ "func", "(", "manager", "*", "configManager", ")", "GetClusterConf", "(", ")", "(", "*", "ClusterConfig", ",", "error", ")", "{", "// get json from kvdb and unmarshal into config", "kvPair", ",", "err", ":=", "manager", ".", "kv", ".", "Get", "(", "filepath", ".", "Join", "(", "baseKey", ",", "clusterKey", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "config", ":=", "new", "(", "ClusterConfig", ")", "\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "kvPair", ".", "Value", ",", "config", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "config", ",", "nil", "\n", "}" ]
// GetClusterConf retrieves cluster level data from kvdb
[ "GetClusterConf", "retrieves", "cluster", "level", "data", "from", "kvdb" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/osdconfig/api.go#L10-L23
144,212
libopenstorage/openstorage
osdconfig/api.go
SetClusterConf
func (manager *configManager) SetClusterConf(config *ClusterConfig) error { if config == nil { return fmt.Errorf("input cannot be nil") } manager.Lock() defer manager.Unlock() // push into kvdb if _, err := manager.kv.Put(filepath.Join(baseKey, clusterKey), config, 0); err != nil { return err } return nil }
go
func (manager *configManager) SetClusterConf(config *ClusterConfig) error { if config == nil { return fmt.Errorf("input cannot be nil") } manager.Lock() defer manager.Unlock() // push into kvdb if _, err := manager.kv.Put(filepath.Join(baseKey, clusterKey), config, 0); err != nil { return err } return nil }
[ "func", "(", "manager", "*", "configManager", ")", "SetClusterConf", "(", "config", "*", "ClusterConfig", ")", "error", "{", "if", "config", "==", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "manager", ".", "Lock", "(", ")", "\n", "defer", "manager", ".", "Unlock", "(", ")", "\n\n", "// push into kvdb", "if", "_", ",", "err", ":=", "manager", ".", "kv", ".", "Put", "(", "filepath", ".", "Join", "(", "baseKey", ",", "clusterKey", ")", ",", "config", ",", "0", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// SetClusterConf sets cluster config in kvdb
[ "SetClusterConf", "sets", "cluster", "config", "in", "kvdb" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/osdconfig/api.go#L26-L40
144,213
libopenstorage/openstorage
osdconfig/api.go
GetNodeConf
func (manager *configManager) GetNodeConf(nodeID string) (*NodeConfig, error) { if len(nodeID) == 0 { return nil, fmt.Errorf("input cannot be nil") } // get json from kvdb and unmarshal into config kvPair, err := manager.kv.Get(getNodeKeyFromNodeID(nodeID)) if err != nil { return nil, err } config := new(NodeConfig) if err = json.Unmarshal(kvPair.Value, config); err != nil { return nil, err } return config, nil }
go
func (manager *configManager) GetNodeConf(nodeID string) (*NodeConfig, error) { if len(nodeID) == 0 { return nil, fmt.Errorf("input cannot be nil") } // get json from kvdb and unmarshal into config kvPair, err := manager.kv.Get(getNodeKeyFromNodeID(nodeID)) if err != nil { return nil, err } config := new(NodeConfig) if err = json.Unmarshal(kvPair.Value, config); err != nil { return nil, err } return config, nil }
[ "func", "(", "manager", "*", "configManager", ")", "GetNodeConf", "(", "nodeID", "string", ")", "(", "*", "NodeConfig", ",", "error", ")", "{", "if", "len", "(", "nodeID", ")", "==", "0", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "// get json from kvdb and unmarshal into config", "kvPair", ",", "err", ":=", "manager", ".", "kv", ".", "Get", "(", "getNodeKeyFromNodeID", "(", "nodeID", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "config", ":=", "new", "(", "NodeConfig", ")", "\n", "if", "err", "=", "json", ".", "Unmarshal", "(", "kvPair", ".", "Value", ",", "config", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "config", ",", "nil", "\n", "}" ]
// GetNodeConf retrieves node config data using nodeID
[ "GetNodeConf", "retrieves", "node", "config", "data", "using", "nodeID" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/osdconfig/api.go#L43-L60
144,214
libopenstorage/openstorage
osdconfig/api.go
SetNodeConf
func (manager *configManager) SetNodeConf(config *NodeConfig) error { if config == nil { return fmt.Errorf("input cannot be nil") } if len(config.NodeId) == 0 { return fmt.Errorf("node id cannot be nil") } manager.Lock() defer manager.Unlock() // push node data into kvdb if _, err := manager.kv.Put(getNodeKeyFromNodeID(config.NodeId), config, 0); err != nil { return err } return nil }
go
func (manager *configManager) SetNodeConf(config *NodeConfig) error { if config == nil { return fmt.Errorf("input cannot be nil") } if len(config.NodeId) == 0 { return fmt.Errorf("node id cannot be nil") } manager.Lock() defer manager.Unlock() // push node data into kvdb if _, err := manager.kv.Put(getNodeKeyFromNodeID(config.NodeId), config, 0); err != nil { return err } return nil }
[ "func", "(", "manager", "*", "configManager", ")", "SetNodeConf", "(", "config", "*", "NodeConfig", ")", "error", "{", "if", "config", "==", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "if", "len", "(", "config", ".", "NodeId", ")", "==", "0", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "manager", ".", "Lock", "(", ")", "\n", "defer", "manager", ".", "Unlock", "(", ")", "\n\n", "// push node data into kvdb", "if", "_", ",", "err", ":=", "manager", ".", "kv", ".", "Put", "(", "getNodeKeyFromNodeID", "(", "config", ".", "NodeId", ")", ",", "config", ",", "0", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// SetNodeConf sets node config data in kvdb
[ "SetNodeConf", "sets", "node", "config", "data", "in", "kvdb" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/osdconfig/api.go#L63-L81
144,215
libopenstorage/openstorage
osdconfig/api.go
DeleteNodeConf
func (manager *configManager) DeleteNodeConf(nodeID string) error { if len(nodeID) == 0 { return fmt.Errorf("node id cannot be nil") } manager.Lock() defer manager.Unlock() // remove dode data from kvdb if _, err := manager.kv.Delete(getNodeKeyFromNodeID(nodeID)); err != nil { return err } return nil }
go
func (manager *configManager) DeleteNodeConf(nodeID string) error { if len(nodeID) == 0 { return fmt.Errorf("node id cannot be nil") } manager.Lock() defer manager.Unlock() // remove dode data from kvdb if _, err := manager.kv.Delete(getNodeKeyFromNodeID(nodeID)); err != nil { return err } return nil }
[ "func", "(", "manager", "*", "configManager", ")", "DeleteNodeConf", "(", "nodeID", "string", ")", "error", "{", "if", "len", "(", "nodeID", ")", "==", "0", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "manager", ".", "Lock", "(", ")", "\n", "defer", "manager", ".", "Unlock", "(", ")", "\n\n", "// remove dode data from kvdb", "if", "_", ",", "err", ":=", "manager", ".", "kv", ".", "Delete", "(", "getNodeKeyFromNodeID", "(", "nodeID", ")", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// DeleteNodeConf deletes node config data in kvdb
[ "DeleteNodeConf", "deletes", "node", "config", "data", "in", "kvdb" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/osdconfig/api.go#L84-L98
144,216
libopenstorage/openstorage
osdconfig/api.go
EnumerateNodeConf
func (manager *configManager) EnumerateNodeConf() (*NodesConfig, error) { keys, err := manager.kv.Keys(filepath.Join(baseKey, nodeKey), "/") if err != nil { return nil, fmt.Errorf("kvdb.Keys() returned error: " + err.Error()) } nodesConfig := new(NodesConfig) *nodesConfig = make([]*NodeConfig, len(keys)) for i, key := range keys { key := key nodeConfig, err := manager.GetNodeConf(key) if err != nil { return nil, err } (*nodesConfig)[i] = nodeConfig } return nodesConfig, nil }
go
func (manager *configManager) EnumerateNodeConf() (*NodesConfig, error) { keys, err := manager.kv.Keys(filepath.Join(baseKey, nodeKey), "/") if err != nil { return nil, fmt.Errorf("kvdb.Keys() returned error: " + err.Error()) } nodesConfig := new(NodesConfig) *nodesConfig = make([]*NodeConfig, len(keys)) for i, key := range keys { key := key nodeConfig, err := manager.GetNodeConf(key) if err != nil { return nil, err } (*nodesConfig)[i] = nodeConfig } return nodesConfig, nil }
[ "func", "(", "manager", "*", "configManager", ")", "EnumerateNodeConf", "(", ")", "(", "*", "NodesConfig", ",", "error", ")", "{", "keys", ",", "err", ":=", "manager", ".", "kv", ".", "Keys", "(", "filepath", ".", "Join", "(", "baseKey", ",", "nodeKey", ")", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", "+", "err", ".", "Error", "(", ")", ")", "\n", "}", "\n\n", "nodesConfig", ":=", "new", "(", "NodesConfig", ")", "\n", "*", "nodesConfig", "=", "make", "(", "[", "]", "*", "NodeConfig", ",", "len", "(", "keys", ")", ")", "\n", "for", "i", ",", "key", ":=", "range", "keys", "{", "key", ":=", "key", "\n", "nodeConfig", ",", "err", ":=", "manager", ".", "GetNodeConf", "(", "key", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "(", "*", "nodesConfig", ")", "[", "i", "]", "=", "nodeConfig", "\n", "}", "\n\n", "return", "nodesConfig", ",", "nil", "\n", "}" ]
// EnumerateNodeConf fetches data for all nodes
[ "EnumerateNodeConf", "fetches", "data", "for", "all", "nodes" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/osdconfig/api.go#L101-L119
144,217
libopenstorage/openstorage
osdconfig/api.go
WatchCluster
func (manager *configManager) WatchCluster(name string, cb func(config *ClusterConfig) error) error { manager.Lock() defer manager.Unlock() if _, present := manager.cbCluster[name]; present { return fmt.Errorf("%s already present", name) } manager.cbCluster[name] = cb return nil }
go
func (manager *configManager) WatchCluster(name string, cb func(config *ClusterConfig) error) error { manager.Lock() defer manager.Unlock() if _, present := manager.cbCluster[name]; present { return fmt.Errorf("%s already present", name) } manager.cbCluster[name] = cb return nil }
[ "func", "(", "manager", "*", "configManager", ")", "WatchCluster", "(", "name", "string", ",", "cb", "func", "(", "config", "*", "ClusterConfig", ")", "error", ")", "error", "{", "manager", ".", "Lock", "(", ")", "\n", "defer", "manager", ".", "Unlock", "(", ")", "\n\n", "if", "_", ",", "present", ":=", "manager", ".", "cbCluster", "[", "name", "]", ";", "present", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "name", ")", "\n", "}", "\n", "manager", ".", "cbCluster", "[", "name", "]", "=", "cb", "\n", "return", "nil", "\n", "}" ]
// WatchCluster registers user defined function as callback and sets a watch for changes // to cluster configuration
[ "WatchCluster", "registers", "user", "defined", "function", "as", "callback", "and", "sets", "a", "watch", "for", "changes", "to", "cluster", "configuration" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/osdconfig/api.go#L123-L132
144,218
libopenstorage/openstorage
osdconfig/api.go
WatchNode
func (manager *configManager) WatchNode(name string, cb func(config *NodeConfig) error) error { manager.Lock() defer manager.Unlock() if _, present := manager.cbNode[name]; present { return fmt.Errorf("%s already present", name) } manager.cbNode[name] = cb return nil }
go
func (manager *configManager) WatchNode(name string, cb func(config *NodeConfig) error) error { manager.Lock() defer manager.Unlock() if _, present := manager.cbNode[name]; present { return fmt.Errorf("%s already present", name) } manager.cbNode[name] = cb return nil }
[ "func", "(", "manager", "*", "configManager", ")", "WatchNode", "(", "name", "string", ",", "cb", "func", "(", "config", "*", "NodeConfig", ")", "error", ")", "error", "{", "manager", ".", "Lock", "(", ")", "\n", "defer", "manager", ".", "Unlock", "(", ")", "\n\n", "if", "_", ",", "present", ":=", "manager", ".", "cbNode", "[", "name", "]", ";", "present", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "name", ")", "\n", "}", "\n", "manager", ".", "cbNode", "[", "name", "]", "=", "cb", "\n", "return", "nil", "\n", "}" ]
// WatchNode registers user defined function as callback and sets a watch for changes // to node configuration
[ "WatchNode", "registers", "user", "defined", "function", "as", "callback", "and", "sets", "a", "watch", "for", "changes", "to", "node", "configuration" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/osdconfig/api.go#L136-L145
144,219
libopenstorage/openstorage
pkg/mount/mount.go
Mount
func (m *DefaultMounter) Mount( source string, target string, fstype string, flags uintptr, data string, timeout int, ) error { return syscall.Mount(source, target, fstype, flags, data) }
go
func (m *DefaultMounter) Mount( source string, target string, fstype string, flags uintptr, data string, timeout int, ) error { return syscall.Mount(source, target, fstype, flags, data) }
[ "func", "(", "m", "*", "DefaultMounter", ")", "Mount", "(", "source", "string", ",", "target", "string", ",", "fstype", "string", ",", "flags", "uintptr", ",", "data", "string", ",", "timeout", "int", ",", ")", "error", "{", "return", "syscall", ".", "Mount", "(", "source", ",", "target", ",", "fstype", ",", "flags", ",", "data", ")", "\n", "}" ]
// Mount default mount implementation is syscall.
[ "Mount", "default", "mount", "implementation", "is", "syscall", "." ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/mount/mount.go#L157-L166
144,220
libopenstorage/openstorage
pkg/mount/mount.go
Unmount
func (m *DefaultMounter) Unmount(target string, flags int, timeout int) error { return syscall.Unmount(target, flags) }
go
func (m *DefaultMounter) Unmount(target string, flags int, timeout int) error { return syscall.Unmount(target, flags) }
[ "func", "(", "m", "*", "DefaultMounter", ")", "Unmount", "(", "target", "string", ",", "flags", "int", ",", "timeout", "int", ")", "error", "{", "return", "syscall", ".", "Unmount", "(", "target", ",", "flags", ")", "\n", "}" ]
// Unmount default unmount implementation is syscall.
[ "Unmount", "default", "unmount", "implementation", "is", "syscall", "." ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/mount/mount.go#L169-L171
144,221
libopenstorage/openstorage
pkg/mount/mount.go
String
func (m *Mounter) String() string { s := struct { mounts DeviceMap paths PathMap allowedDirs []string trashLocation string }{ mounts: m.mounts, paths: m.paths, allowedDirs: m.allowedDirs, trashLocation: m.trashLocation, } return fmt.Sprintf("%#v", s) }
go
func (m *Mounter) String() string { s := struct { mounts DeviceMap paths PathMap allowedDirs []string trashLocation string }{ mounts: m.mounts, paths: m.paths, allowedDirs: m.allowedDirs, trashLocation: m.trashLocation, } return fmt.Sprintf("%#v", s) }
[ "func", "(", "m", "*", "Mounter", ")", "String", "(", ")", "string", "{", "s", ":=", "struct", "{", "mounts", "DeviceMap", "\n", "paths", "PathMap", "\n", "allowedDirs", "[", "]", "string", "\n", "trashLocation", "string", "\n", "}", "{", "mounts", ":", "m", ".", "mounts", ",", "paths", ":", "m", ".", "paths", ",", "allowedDirs", ":", "m", ".", "allowedDirs", ",", "trashLocation", ":", "m", ".", "trashLocation", ",", "}", "\n\n", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "s", ")", "\n", "}" ]
// String representation of Mounter
[ "String", "representation", "of", "Mounter" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/mount/mount.go#L174-L188
144,222
libopenstorage/openstorage
pkg/mount/mount.go
Inspect
func (m *Mounter) Inspect(sourcePath string) []*PathInfo { m.Lock() defer m.Unlock() v, ok := m.mounts[sourcePath] if !ok { return nil } return v.Mountpoint }
go
func (m *Mounter) Inspect(sourcePath string) []*PathInfo { m.Lock() defer m.Unlock() v, ok := m.mounts[sourcePath] if !ok { return nil } return v.Mountpoint }
[ "func", "(", "m", "*", "Mounter", ")", "Inspect", "(", "sourcePath", "string", ")", "[", "]", "*", "PathInfo", "{", "m", ".", "Lock", "(", ")", "\n", "defer", "m", ".", "Unlock", "(", ")", "\n\n", "v", ",", "ok", ":=", "m", ".", "mounts", "[", "sourcePath", "]", "\n", "if", "!", "ok", "{", "return", "nil", "\n", "}", "\n", "return", "v", ".", "Mountpoint", "\n", "}" ]
// Inspect mount table for device
[ "Inspect", "mount", "table", "for", "device" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/mount/mount.go#L191-L200
144,223
libopenstorage/openstorage
pkg/mount/mount.go
Mounts
func (m *Mounter) Mounts(sourcePath string) []string { m.Lock() defer m.Unlock() v, ok := m.mounts[sourcePath] if !ok { return nil } mounts := make([]string, len(v.Mountpoint)) for i, v := range v.Mountpoint { mounts[i] = v.Path } return mounts }
go
func (m *Mounter) Mounts(sourcePath string) []string { m.Lock() defer m.Unlock() v, ok := m.mounts[sourcePath] if !ok { return nil } mounts := make([]string, len(v.Mountpoint)) for i, v := range v.Mountpoint { mounts[i] = v.Path } return mounts }
[ "func", "(", "m", "*", "Mounter", ")", "Mounts", "(", "sourcePath", "string", ")", "[", "]", "string", "{", "m", ".", "Lock", "(", ")", "\n", "defer", "m", ".", "Unlock", "(", ")", "\n\n", "v", ",", "ok", ":=", "m", ".", "mounts", "[", "sourcePath", "]", "\n", "if", "!", "ok", "{", "return", "nil", "\n", "}", "\n\n", "mounts", ":=", "make", "(", "[", "]", "string", ",", "len", "(", "v", ".", "Mountpoint", ")", ")", "\n", "for", "i", ",", "v", ":=", "range", "v", ".", "Mountpoint", "{", "mounts", "[", "i", "]", "=", "v", ".", "Path", "\n", "}", "\n\n", "return", "mounts", "\n", "}" ]
// Mounts returns mount table for device
[ "Mounts", "returns", "mount", "table", "for", "device" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/mount/mount.go#L203-L218
144,224
libopenstorage/openstorage
pkg/mount/mount.go
GetSourcePaths
func (m *Mounter) GetSourcePaths() []string { m.Lock() defer m.Unlock() sourcePaths := make([]string, len(m.mounts)) i := 0 for path := range m.mounts { sourcePaths[i] = path i++ } return sourcePaths }
go
func (m *Mounter) GetSourcePaths() []string { m.Lock() defer m.Unlock() sourcePaths := make([]string, len(m.mounts)) i := 0 for path := range m.mounts { sourcePaths[i] = path i++ } return sourcePaths }
[ "func", "(", "m", "*", "Mounter", ")", "GetSourcePaths", "(", ")", "[", "]", "string", "{", "m", ".", "Lock", "(", ")", "\n", "defer", "m", ".", "Unlock", "(", ")", "\n\n", "sourcePaths", ":=", "make", "(", "[", "]", "string", ",", "len", "(", "m", ".", "mounts", ")", ")", "\n", "i", ":=", "0", "\n", "for", "path", ":=", "range", "m", ".", "mounts", "{", "sourcePaths", "[", "i", "]", "=", "path", "\n", "i", "++", "\n", "}", "\n", "return", "sourcePaths", "\n", "}" ]
// GetSourcePaths returns all source paths from the mount table
[ "GetSourcePaths", "returns", "all", "source", "paths", "from", "the", "mount", "table" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/mount/mount.go#L221-L232
144,225
libopenstorage/openstorage
pkg/mount/mount.go
HasMounts
func (m *Mounter) HasMounts(sourcePath string) int { m.Lock() defer m.Unlock() v, ok := m.mounts[sourcePath] if !ok { return 0 } return len(v.Mountpoint) }
go
func (m *Mounter) HasMounts(sourcePath string) int { m.Lock() defer m.Unlock() v, ok := m.mounts[sourcePath] if !ok { return 0 } return len(v.Mountpoint) }
[ "func", "(", "m", "*", "Mounter", ")", "HasMounts", "(", "sourcePath", "string", ")", "int", "{", "m", ".", "Lock", "(", ")", "\n", "defer", "m", ".", "Unlock", "(", ")", "\n\n", "v", ",", "ok", ":=", "m", ".", "mounts", "[", "sourcePath", "]", "\n", "if", "!", "ok", "{", "return", "0", "\n", "}", "\n", "return", "len", "(", "v", ".", "Mountpoint", ")", "\n", "}" ]
// HasMounts determines returns the number of mounts for the device.
[ "HasMounts", "determines", "returns", "the", "number", "of", "mounts", "for", "the", "device", "." ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/mount/mount.go#L235-L244
144,226
libopenstorage/openstorage
pkg/mount/mount.go
Exists
func (m *Mounter) Exists(sourcePath string, path string) (bool, error) { m.Lock() defer m.Unlock() v, ok := m.mounts[sourcePath] if !ok { return false, ErrEnoent } for _, p := range v.Mountpoint { if p.Path == path { return true, nil } } return false, nil }
go
func (m *Mounter) Exists(sourcePath string, path string) (bool, error) { m.Lock() defer m.Unlock() v, ok := m.mounts[sourcePath] if !ok { return false, ErrEnoent } for _, p := range v.Mountpoint { if p.Path == path { return true, nil } } return false, nil }
[ "func", "(", "m", "*", "Mounter", ")", "Exists", "(", "sourcePath", "string", ",", "path", "string", ")", "(", "bool", ",", "error", ")", "{", "m", ".", "Lock", "(", ")", "\n", "defer", "m", ".", "Unlock", "(", ")", "\n\n", "v", ",", "ok", ":=", "m", ".", "mounts", "[", "sourcePath", "]", "\n", "if", "!", "ok", "{", "return", "false", ",", "ErrEnoent", "\n", "}", "\n", "for", "_", ",", "p", ":=", "range", "v", ".", "Mountpoint", "{", "if", "p", ".", "Path", "==", "path", "{", "return", "true", ",", "nil", "\n", "}", "\n", "}", "\n", "return", "false", ",", "nil", "\n", "}" ]
// Exists scans mountpaths for specified device and returns true if path is one of the // mountpaths. ErrEnoent may be retuned if the device is not found
[ "Exists", "scans", "mountpaths", "for", "specified", "device", "and", "returns", "true", "if", "path", "is", "one", "of", "the", "mountpaths", ".", "ErrEnoent", "may", "be", "retuned", "if", "the", "device", "is", "not", "found" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/mount/mount.go#L263-L277
144,227
libopenstorage/openstorage
pkg/mount/mount.go
GetRootPath
func (m *Mounter) GetRootPath(mountPath string) (string, error) { m.Lock() defer m.Unlock() for _, v := range m.mounts { for _, p := range v.Mountpoint { if p.Path == mountPath { return p.Root, nil } } } return "", ErrEnoent }
go
func (m *Mounter) GetRootPath(mountPath string) (string, error) { m.Lock() defer m.Unlock() for _, v := range m.mounts { for _, p := range v.Mountpoint { if p.Path == mountPath { return p.Root, nil } } } return "", ErrEnoent }
[ "func", "(", "m", "*", "Mounter", ")", "GetRootPath", "(", "mountPath", "string", ")", "(", "string", ",", "error", ")", "{", "m", ".", "Lock", "(", ")", "\n", "defer", "m", ".", "Unlock", "(", ")", "\n\n", "for", "_", ",", "v", ":=", "range", "m", ".", "mounts", "{", "for", "_", ",", "p", ":=", "range", "v", ".", "Mountpoint", "{", "if", "p", ".", "Path", "==", "mountPath", "{", "return", "p", ".", "Root", ",", "nil", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "\"", "\"", ",", "ErrEnoent", "\n", "}" ]
// GetRootPath scans mounts for a specified mountPath and return the // rootPath if found or returns an ErrEnoent
[ "GetRootPath", "scans", "mounts", "for", "a", "specified", "mountPath", "and", "return", "the", "rootPath", "if", "found", "or", "returns", "an", "ErrEnoent" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/mount/mount.go#L281-L293
144,228
libopenstorage/openstorage
pkg/mount/mount.go
GetSourcePath
func (m *Mounter) GetSourcePath(mountPath string) (string, error) { m.Lock() defer m.Unlock() for k, v := range m.mounts { for _, p := range v.Mountpoint { if p.Path == mountPath { return k, nil } } } return "", ErrEnoent }
go
func (m *Mounter) GetSourcePath(mountPath string) (string, error) { m.Lock() defer m.Unlock() for k, v := range m.mounts { for _, p := range v.Mountpoint { if p.Path == mountPath { return k, nil } } } return "", ErrEnoent }
[ "func", "(", "m", "*", "Mounter", ")", "GetSourcePath", "(", "mountPath", "string", ")", "(", "string", ",", "error", ")", "{", "m", ".", "Lock", "(", ")", "\n", "defer", "m", ".", "Unlock", "(", ")", "\n\n", "for", "k", ",", "v", ":=", "range", "m", ".", "mounts", "{", "for", "_", ",", "p", ":=", "range", "v", ".", "Mountpoint", "{", "if", "p", ".", "Path", "==", "mountPath", "{", "return", "k", ",", "nil", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "\"", "\"", ",", "ErrEnoent", "\n", "}" ]
// GetSourcePath scans mount for a specified mountPath and returns the sourcePath // if found or returnes an ErrEnoent
[ "GetSourcePath", "scans", "mount", "for", "a", "specified", "mountPath", "and", "returns", "the", "sourcePath", "if", "found", "or", "returnes", "an", "ErrEnoent" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/mount/mount.go#L297-L309
144,229
libopenstorage/openstorage
pkg/mount/mount.go
reload
func (m *Mounter) reload(device string, newM *Info) error { m.Lock() defer m.Unlock() // New mountable has no mounts, delete old mounts. if newM == nil { delete(m.mounts, device) return nil } // Old mountable had no mounts, copy over new mounts. oldM, ok := m.mounts[device] if !ok { m.mounts[device] = newM return nil } // Overwrite old mount entries into new mount table, preserving refcnt. for _, oldP := range oldM.Mountpoint { for j, newP := range newM.Mountpoint { if newP.Path == oldP.Path { newM.Mountpoint[j] = oldP break } } } // Purge old mounts. m.mounts[device] = newM return nil }
go
func (m *Mounter) reload(device string, newM *Info) error { m.Lock() defer m.Unlock() // New mountable has no mounts, delete old mounts. if newM == nil { delete(m.mounts, device) return nil } // Old mountable had no mounts, copy over new mounts. oldM, ok := m.mounts[device] if !ok { m.mounts[device] = newM return nil } // Overwrite old mount entries into new mount table, preserving refcnt. for _, oldP := range oldM.Mountpoint { for j, newP := range newM.Mountpoint { if newP.Path == oldP.Path { newM.Mountpoint[j] = oldP break } } } // Purge old mounts. m.mounts[device] = newM return nil }
[ "func", "(", "m", "*", "Mounter", ")", "reload", "(", "device", "string", ",", "newM", "*", "Info", ")", "error", "{", "m", ".", "Lock", "(", ")", "\n", "defer", "m", ".", "Unlock", "(", ")", "\n\n", "// New mountable has no mounts, delete old mounts.", "if", "newM", "==", "nil", "{", "delete", "(", "m", ".", "mounts", ",", "device", ")", "\n", "return", "nil", "\n", "}", "\n\n", "// Old mountable had no mounts, copy over new mounts.", "oldM", ",", "ok", ":=", "m", ".", "mounts", "[", "device", "]", "\n", "if", "!", "ok", "{", "m", ".", "mounts", "[", "device", "]", "=", "newM", "\n", "return", "nil", "\n", "}", "\n\n", "// Overwrite old mount entries into new mount table, preserving refcnt.", "for", "_", ",", "oldP", ":=", "range", "oldM", ".", "Mountpoint", "{", "for", "j", ",", "newP", ":=", "range", "newM", ".", "Mountpoint", "{", "if", "newP", ".", "Path", "==", "oldP", ".", "Path", "{", "newM", ".", "Mountpoint", "[", "j", "]", "=", "oldP", "\n", "break", "\n", "}", "\n", "}", "\n", "}", "\n\n", "// Purge old mounts.", "m", ".", "mounts", "[", "device", "]", "=", "newM", "\n", "return", "nil", "\n", "}" ]
// reload from newM
[ "reload", "from", "newM" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/mount/mount.go#L330-L360
144,230
libopenstorage/openstorage
pkg/mount/mount.go
Unmount
func (m *Mounter) Unmount( devPath string, path string, flags int, timeout int, opts map[string]string, ) error { m.Lock() // device gets overwritten if opts specifies fuse mount with // options.OptionsDeviceFuseMount. device := devPath path = normalizeMountPath(path) if value, ok := opts[options.OptionsDeviceFuseMount]; ok { // fuse mounts show-up with this key as device. device = value } info, ok := m.mounts[device] if !ok { m.Unlock() logrus.Warnf("Unable to unmount device %q path %q: %v", devPath, path, ErrEnoent.Error()) return ErrEnoent } m.Unlock() info.Lock() defer info.Unlock() for i, p := range info.Mountpoint { if p.Path != path { continue } err := m.mountImpl.Unmount(path, flags, timeout) if err != nil { return err } // Blow away this mountpoint. info.Mountpoint[i] = info.Mountpoint[len(info.Mountpoint)-1] info.Mountpoint = info.Mountpoint[0 : len(info.Mountpoint)-1] m.maybeRemoveDevice(device) if options.IsBoolOptionSet(opts, options.OptionsDeleteAfterUnmount) { m.RemoveMountPath(path, opts) } return nil } logrus.Warnf("Device %q is not mounted at path %q", device, path) return nil }
go
func (m *Mounter) Unmount( devPath string, path string, flags int, timeout int, opts map[string]string, ) error { m.Lock() // device gets overwritten if opts specifies fuse mount with // options.OptionsDeviceFuseMount. device := devPath path = normalizeMountPath(path) if value, ok := opts[options.OptionsDeviceFuseMount]; ok { // fuse mounts show-up with this key as device. device = value } info, ok := m.mounts[device] if !ok { m.Unlock() logrus.Warnf("Unable to unmount device %q path %q: %v", devPath, path, ErrEnoent.Error()) return ErrEnoent } m.Unlock() info.Lock() defer info.Unlock() for i, p := range info.Mountpoint { if p.Path != path { continue } err := m.mountImpl.Unmount(path, flags, timeout) if err != nil { return err } // Blow away this mountpoint. info.Mountpoint[i] = info.Mountpoint[len(info.Mountpoint)-1] info.Mountpoint = info.Mountpoint[0 : len(info.Mountpoint)-1] m.maybeRemoveDevice(device) if options.IsBoolOptionSet(opts, options.OptionsDeleteAfterUnmount) { m.RemoveMountPath(path, opts) } return nil } logrus.Warnf("Device %q is not mounted at path %q", device, path) return nil }
[ "func", "(", "m", "*", "Mounter", ")", "Unmount", "(", "devPath", "string", ",", "path", "string", ",", "flags", "int", ",", "timeout", "int", ",", "opts", "map", "[", "string", "]", "string", ",", ")", "error", "{", "m", ".", "Lock", "(", ")", "\n", "// device gets overwritten if opts specifies fuse mount with", "// options.OptionsDeviceFuseMount.", "device", ":=", "devPath", "\n", "path", "=", "normalizeMountPath", "(", "path", ")", "\n", "if", "value", ",", "ok", ":=", "opts", "[", "options", ".", "OptionsDeviceFuseMount", "]", ";", "ok", "{", "// fuse mounts show-up with this key as device.", "device", "=", "value", "\n", "}", "\n", "info", ",", "ok", ":=", "m", ".", "mounts", "[", "device", "]", "\n", "if", "!", "ok", "{", "m", ".", "Unlock", "(", ")", "\n", "logrus", ".", "Warnf", "(", "\"", "\"", ",", "devPath", ",", "path", ",", "ErrEnoent", ".", "Error", "(", ")", ")", "\n", "return", "ErrEnoent", "\n", "}", "\n", "m", ".", "Unlock", "(", ")", "\n", "info", ".", "Lock", "(", ")", "\n", "defer", "info", ".", "Unlock", "(", ")", "\n", "for", "i", ",", "p", ":=", "range", "info", ".", "Mountpoint", "{", "if", "p", ".", "Path", "!=", "path", "{", "continue", "\n", "}", "\n", "err", ":=", "m", ".", "mountImpl", ".", "Unmount", "(", "path", ",", "flags", ",", "timeout", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "// Blow away this mountpoint.", "info", ".", "Mountpoint", "[", "i", "]", "=", "info", ".", "Mountpoint", "[", "len", "(", "info", ".", "Mountpoint", ")", "-", "1", "]", "\n", "info", ".", "Mountpoint", "=", "info", ".", "Mountpoint", "[", "0", ":", "len", "(", "info", ".", "Mountpoint", ")", "-", "1", "]", "\n", "m", ".", "maybeRemoveDevice", "(", "device", ")", "\n", "if", "options", ".", "IsBoolOptionSet", "(", "opts", ",", "options", ".", "OptionsDeleteAfterUnmount", ")", "{", "m", ".", "RemoveMountPath", "(", "path", ",", "opts", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}", "\n", "logrus", ".", "Warnf", "(", "\"", "\"", ",", "device", ",", "path", ")", "\n", "return", "nil", "\n", "}" ]
// Unmount device at mountpoint and from the matrix. // ErrEnoent is returned if the device or mountpoint for the device is not found.
[ "Unmount", "device", "at", "mountpoint", "and", "from", "the", "matrix", ".", "ErrEnoent", "is", "returned", "if", "the", "device", "or", "mountpoint", "for", "the", "device", "is", "not", "found", "." ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/mount/mount.go#L589-L635
144,231
libopenstorage/openstorage
pkg/mount/mount.go
RemoveMountPath
func (m *Mounter) RemoveMountPath(mountPath string, opts map[string]string) error { if _, err := os.Stat(mountPath); err == nil { if options.IsBoolOptionSet(opts, options.OptionsWaitBeforeDelete) { hasher := md5.New() hasher.Write([]byte(mountPath)) symlinkName := hex.EncodeToString(hasher.Sum(nil)) symlinkPath := path.Join(m.trashLocation, symlinkName) if err = os.Symlink(mountPath, symlinkPath); err != nil { if !os.IsExist(err) { logrus.Errorf("Error creating sym link %s => %s. Err: %v", symlinkPath, mountPath, err) } } if _, err = sched.Instance().Schedule( func(sched.Interval) { if err = m.removeMountPath(mountPath); err != nil { return } if err = os.Remove(symlinkPath); err != nil { return } }, sched.Periodic(time.Second), time.Now().Add(mountPathRemoveDelay), true /* run only once */); err != nil { logrus.Errorf("Failed to schedule task to remove path:%v. Err: %v", mountPath, err) return err } } else { return m.removeMountPath(mountPath) } } return nil }
go
func (m *Mounter) RemoveMountPath(mountPath string, opts map[string]string) error { if _, err := os.Stat(mountPath); err == nil { if options.IsBoolOptionSet(opts, options.OptionsWaitBeforeDelete) { hasher := md5.New() hasher.Write([]byte(mountPath)) symlinkName := hex.EncodeToString(hasher.Sum(nil)) symlinkPath := path.Join(m.trashLocation, symlinkName) if err = os.Symlink(mountPath, symlinkPath); err != nil { if !os.IsExist(err) { logrus.Errorf("Error creating sym link %s => %s. Err: %v", symlinkPath, mountPath, err) } } if _, err = sched.Instance().Schedule( func(sched.Interval) { if err = m.removeMountPath(mountPath); err != nil { return } if err = os.Remove(symlinkPath); err != nil { return } }, sched.Periodic(time.Second), time.Now().Add(mountPathRemoveDelay), true /* run only once */); err != nil { logrus.Errorf("Failed to schedule task to remove path:%v. Err: %v", mountPath, err) return err } } else { return m.removeMountPath(mountPath) } } return nil }
[ "func", "(", "m", "*", "Mounter", ")", "RemoveMountPath", "(", "mountPath", "string", ",", "opts", "map", "[", "string", "]", "string", ")", "error", "{", "if", "_", ",", "err", ":=", "os", ".", "Stat", "(", "mountPath", ")", ";", "err", "==", "nil", "{", "if", "options", ".", "IsBoolOptionSet", "(", "opts", ",", "options", ".", "OptionsWaitBeforeDelete", ")", "{", "hasher", ":=", "md5", ".", "New", "(", ")", "\n", "hasher", ".", "Write", "(", "[", "]", "byte", "(", "mountPath", ")", ")", "\n", "symlinkName", ":=", "hex", ".", "EncodeToString", "(", "hasher", ".", "Sum", "(", "nil", ")", ")", "\n", "symlinkPath", ":=", "path", ".", "Join", "(", "m", ".", "trashLocation", ",", "symlinkName", ")", "\n\n", "if", "err", "=", "os", ".", "Symlink", "(", "mountPath", ",", "symlinkPath", ")", ";", "err", "!=", "nil", "{", "if", "!", "os", ".", "IsExist", "(", "err", ")", "{", "logrus", ".", "Errorf", "(", "\"", "\"", ",", "symlinkPath", ",", "mountPath", ",", "err", ")", "\n", "}", "\n", "}", "\n\n", "if", "_", ",", "err", "=", "sched", ".", "Instance", "(", ")", ".", "Schedule", "(", "func", "(", "sched", ".", "Interval", ")", "{", "if", "err", "=", "m", ".", "removeMountPath", "(", "mountPath", ")", ";", "err", "!=", "nil", "{", "return", "\n", "}", "\n\n", "if", "err", "=", "os", ".", "Remove", "(", "symlinkPath", ")", ";", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "}", ",", "sched", ".", "Periodic", "(", "time", ".", "Second", ")", ",", "time", ".", "Now", "(", ")", ".", "Add", "(", "mountPathRemoveDelay", ")", ",", "true", "/* run only once */", ")", ";", "err", "!=", "nil", "{", "logrus", ".", "Errorf", "(", "\"", "\"", ",", "mountPath", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n", "}", "else", "{", "return", "m", ".", "removeMountPath", "(", "mountPath", ")", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// RemoveMountPath makes the path writeable and removes it after a fixed delay
[ "RemoveMountPath", "makes", "the", "path", "writeable", "and", "removes", "it", "after", "a", "fixed", "delay" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/mount/mount.go#L685-L721
144,232
libopenstorage/openstorage
pkg/mount/mount.go
New
func New( mounterType MountType, mountImpl MountImpl, identifiers []string, customMounter CustomMounter, allowedDirs []string, trashLocation string, ) (Manager, error) { if mountImpl == nil { mountImpl = &DefaultMounter{} } switch mounterType { case DeviceMount: return NewDeviceMounter(identifiers, mountImpl, allowedDirs, trashLocation) case NFSMount: return NewNFSMounter(identifiers, mountImpl, allowedDirs) case BindMount: return NewBindMounter(identifiers, mountImpl, allowedDirs, trashLocation) case CustomMount: return NewCustomMounter(identifiers, mountImpl, customMounter, allowedDirs) } return nil, ErrUnsupported }
go
func New( mounterType MountType, mountImpl MountImpl, identifiers []string, customMounter CustomMounter, allowedDirs []string, trashLocation string, ) (Manager, error) { if mountImpl == nil { mountImpl = &DefaultMounter{} } switch mounterType { case DeviceMount: return NewDeviceMounter(identifiers, mountImpl, allowedDirs, trashLocation) case NFSMount: return NewNFSMounter(identifiers, mountImpl, allowedDirs) case BindMount: return NewBindMounter(identifiers, mountImpl, allowedDirs, trashLocation) case CustomMount: return NewCustomMounter(identifiers, mountImpl, customMounter, allowedDirs) } return nil, ErrUnsupported }
[ "func", "New", "(", "mounterType", "MountType", ",", "mountImpl", "MountImpl", ",", "identifiers", "[", "]", "string", ",", "customMounter", "CustomMounter", ",", "allowedDirs", "[", "]", "string", ",", "trashLocation", "string", ",", ")", "(", "Manager", ",", "error", ")", "{", "if", "mountImpl", "==", "nil", "{", "mountImpl", "=", "&", "DefaultMounter", "{", "}", "\n", "}", "\n\n", "switch", "mounterType", "{", "case", "DeviceMount", ":", "return", "NewDeviceMounter", "(", "identifiers", ",", "mountImpl", ",", "allowedDirs", ",", "trashLocation", ")", "\n", "case", "NFSMount", ":", "return", "NewNFSMounter", "(", "identifiers", ",", "mountImpl", ",", "allowedDirs", ")", "\n", "case", "BindMount", ":", "return", "NewBindMounter", "(", "identifiers", ",", "mountImpl", ",", "allowedDirs", ",", "trashLocation", ")", "\n", "case", "CustomMount", ":", "return", "NewCustomMounter", "(", "identifiers", ",", "mountImpl", ",", "customMounter", ",", "allowedDirs", ")", "\n", "}", "\n", "return", "nil", ",", "ErrUnsupported", "\n", "}" ]
// New returns a new Mount Manager
[ "New", "returns", "a", "new", "Mount", "Manager" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/mount/mount.go#L785-L809
144,233
libopenstorage/openstorage
graph/drivers/chainfs/unsupported.go
Init
func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (graphdriver.Driver, error) { return nil, errUnsupported }
go
func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (graphdriver.Driver, error) { return nil, errUnsupported }
[ "func", "Init", "(", "home", "string", ",", "options", "[", "]", "string", ",", "uidMaps", ",", "gidMaps", "[", "]", "idtools", ".", "IDMap", ")", "(", "graphdriver", ".", "Driver", ",", "error", ")", "{", "return", "nil", ",", "errUnsupported", "\n", "}" ]
// Init initializes the graphdriver
[ "Init", "initializes", "the", "graphdriver" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/graph/drivers/chainfs/unsupported.go#L25-L27
144,234
libopenstorage/openstorage
api/status.go
StatusSimpleValueOf
func StatusSimpleValueOf(s string) (Status, error) { obj, err := simpleValueOf("status", Status_value, s) return Status(obj), err }
go
func StatusSimpleValueOf(s string) (Status, error) { obj, err := simpleValueOf("status", Status_value, s) return Status(obj), err }
[ "func", "StatusSimpleValueOf", "(", "s", "string", ")", "(", "Status", ",", "error", ")", "{", "obj", ",", "err", ":=", "simpleValueOf", "(", "\"", "\"", ",", "Status_value", ",", "s", ")", "\n", "return", "Status", "(", "obj", ")", ",", "err", "\n", "}" ]
// StatusSimpleValueOf returns the string format of Status
[ "StatusSimpleValueOf", "returns", "the", "string", "format", "of", "Status" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/status.go#L35-L38
144,235
gorilla/rpc
json/server.go
Method
func (c *CodecRequest) Method() (string, error) { if c.err == nil { return c.request.Method, nil } return "", c.err }
go
func (c *CodecRequest) Method() (string, error) { if c.err == nil { return c.request.Method, nil } return "", c.err }
[ "func", "(", "c", "*", "CodecRequest", ")", "Method", "(", ")", "(", "string", ",", "error", ")", "{", "if", "c", ".", "err", "==", "nil", "{", "return", "c", ".", "request", ".", "Method", ",", "nil", "\n", "}", "\n", "return", "\"", "\"", ",", "c", ".", "err", "\n", "}" ]
// Method returns the RPC method for the current request. // // The method uses a dotted notation as in "Service.Method".
[ "Method", "returns", "the", "RPC", "method", "for", "the", "current", "request", ".", "The", "method", "uses", "a", "dotted", "notation", "as", "in", "Service", ".", "Method", "." ]
bffcfa752ad4e523cc8f720afeb5b985ed41ae16
https://github.com/gorilla/rpc/blob/bffcfa752ad4e523cc8f720afeb5b985ed41ae16/json/server.go#L85-L90
144,236
gorilla/rpc
json/server.go
WriteResponse
func (c *CodecRequest) WriteResponse(w http.ResponseWriter, reply interface{}, methodErr error) error { if c.err != nil { return c.err } res := &serverResponse{ Result: reply, Error: &null, Id: c.request.Id, } if methodErr != nil { // Propagate error message as string. res.Error = methodErr.Error() // Result must be null if there was an error invoking the method. // http://json-rpc.org/wiki/specification#a1.2Response res.Result = &null } if c.request.Id == nil { // Id is null for notifications and they don't have a response. res.Id = &null } else { w.Header().Set("Content-Type", "application/json; charset=utf-8") encoder := json.NewEncoder(w) c.err = encoder.Encode(res) } return c.err }
go
func (c *CodecRequest) WriteResponse(w http.ResponseWriter, reply interface{}, methodErr error) error { if c.err != nil { return c.err } res := &serverResponse{ Result: reply, Error: &null, Id: c.request.Id, } if methodErr != nil { // Propagate error message as string. res.Error = methodErr.Error() // Result must be null if there was an error invoking the method. // http://json-rpc.org/wiki/specification#a1.2Response res.Result = &null } if c.request.Id == nil { // Id is null for notifications and they don't have a response. res.Id = &null } else { w.Header().Set("Content-Type", "application/json; charset=utf-8") encoder := json.NewEncoder(w) c.err = encoder.Encode(res) } return c.err }
[ "func", "(", "c", "*", "CodecRequest", ")", "WriteResponse", "(", "w", "http", ".", "ResponseWriter", ",", "reply", "interface", "{", "}", ",", "methodErr", "error", ")", "error", "{", "if", "c", ".", "err", "!=", "nil", "{", "return", "c", ".", "err", "\n", "}", "\n", "res", ":=", "&", "serverResponse", "{", "Result", ":", "reply", ",", "Error", ":", "&", "null", ",", "Id", ":", "c", ".", "request", ".", "Id", ",", "}", "\n", "if", "methodErr", "!=", "nil", "{", "// Propagate error message as string.", "res", ".", "Error", "=", "methodErr", ".", "Error", "(", ")", "\n", "// Result must be null if there was an error invoking the method.", "// http://json-rpc.org/wiki/specification#a1.2Response", "res", ".", "Result", "=", "&", "null", "\n", "}", "\n", "if", "c", ".", "request", ".", "Id", "==", "nil", "{", "// Id is null for notifications and they don't have a response.", "res", ".", "Id", "=", "&", "null", "\n", "}", "else", "{", "w", ".", "Header", "(", ")", ".", "Set", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "encoder", ":=", "json", ".", "NewEncoder", "(", "w", ")", "\n", "c", ".", "err", "=", "encoder", ".", "Encode", "(", "res", ")", "\n", "}", "\n", "return", "c", ".", "err", "\n", "}" ]
// WriteResponse encodes the response and writes it to the ResponseWriter. // // The err parameter is the error resulted from calling the RPC method, // or nil if there was no error.
[ "WriteResponse", "encodes", "the", "response", "and", "writes", "it", "to", "the", "ResponseWriter", ".", "The", "err", "parameter", "is", "the", "error", "resulted", "from", "calling", "the", "RPC", "method", "or", "nil", "if", "there", "was", "no", "error", "." ]
bffcfa752ad4e523cc8f720afeb5b985ed41ae16
https://github.com/gorilla/rpc/blob/bffcfa752ad4e523cc8f720afeb5b985ed41ae16/json/server.go#L111-L136
144,237
gorilla/rpc
v2/server.go
HasMethod
func (s *Server) HasMethod(method string) bool { if _, _, err := s.services.get(method); err == nil { return true } return false }
go
func (s *Server) HasMethod(method string) bool { if _, _, err := s.services.get(method); err == nil { return true } return false }
[ "func", "(", "s", "*", "Server", ")", "HasMethod", "(", "method", "string", ")", "bool", "{", "if", "_", ",", "_", ",", "err", ":=", "s", ".", "services", ".", "get", "(", "method", ")", ";", "err", "==", "nil", "{", "return", "true", "\n", "}", "\n", "return", "false", "\n", "}" ]
// HasMethod returns true if the given method is registered. // // The method uses a dotted notation as in "Service.Method".
[ "HasMethod", "returns", "true", "if", "the", "given", "method", "is", "registered", ".", "The", "method", "uses", "a", "dotted", "notation", "as", "in", "Service", ".", "Method", "." ]
bffcfa752ad4e523cc8f720afeb5b985ed41ae16
https://github.com/gorilla/rpc/blob/bffcfa752ad4e523cc8f720afeb5b985ed41ae16/v2/server.go#L139-L144
144,238
gorilla/rpc
map.go
register
func (m *serviceMap) register(rcvr interface{}, name string, passReq bool) error { // Setup service. s := &service{ name: name, rcvr: reflect.ValueOf(rcvr), rcvrType: reflect.TypeOf(rcvr), methods: make(map[string]*serviceMethod), passReq: passReq, } if name == "" { s.name = reflect.Indirect(s.rcvr).Type().Name() if !isExported(s.name) { return fmt.Errorf("rpc: type %q is not exported", s.name) } } if s.name == "" { return fmt.Errorf("rpc: no service name for type %q", s.rcvrType.String()) } // Setup methods. for i := 0; i < s.rcvrType.NumMethod(); i++ { method := s.rcvrType.Method(i) mtype := method.Type // offset the parameter indexes by one if the // service methods accept an HTTP request pointer var paramOffset int if passReq { paramOffset = 1 } else { paramOffset = 0 } // Method must be exported. if method.PkgPath != "" { continue } // Method needs four ins: receiver, *http.Request, *args, *reply. if mtype.NumIn() != 3+paramOffset { continue } // If the service methods accept an HTTP request pointer if passReq { // First argument must be a pointer and must be http.Request. reqType := mtype.In(1) if reqType.Kind() != reflect.Ptr || reqType.Elem() != typeOfRequest { continue } } // Next argument must be a pointer and must be exported. args := mtype.In(1 + paramOffset) if args.Kind() != reflect.Ptr || !isExportedOrBuiltin(args) { continue } // Next argument must be a pointer and must be exported. reply := mtype.In(2 + paramOffset) if reply.Kind() != reflect.Ptr || !isExportedOrBuiltin(reply) { continue } // Method needs one out: error. if mtype.NumOut() != 1 { continue } if returnType := mtype.Out(0); returnType != typeOfError { continue } s.methods[method.Name] = &serviceMethod{ method: method, argsType: args.Elem(), replyType: reply.Elem(), } } if len(s.methods) == 0 { return fmt.Errorf("rpc: %q has no exported methods of suitable type", s.name) } // Add to the map. m.mutex.Lock() defer m.mutex.Unlock() if m.services == nil { m.services = make(map[string]*service) } else if _, ok := m.services[s.name]; ok { return fmt.Errorf("rpc: service already defined: %q", s.name) } m.services[s.name] = s return nil }
go
func (m *serviceMap) register(rcvr interface{}, name string, passReq bool) error { // Setup service. s := &service{ name: name, rcvr: reflect.ValueOf(rcvr), rcvrType: reflect.TypeOf(rcvr), methods: make(map[string]*serviceMethod), passReq: passReq, } if name == "" { s.name = reflect.Indirect(s.rcvr).Type().Name() if !isExported(s.name) { return fmt.Errorf("rpc: type %q is not exported", s.name) } } if s.name == "" { return fmt.Errorf("rpc: no service name for type %q", s.rcvrType.String()) } // Setup methods. for i := 0; i < s.rcvrType.NumMethod(); i++ { method := s.rcvrType.Method(i) mtype := method.Type // offset the parameter indexes by one if the // service methods accept an HTTP request pointer var paramOffset int if passReq { paramOffset = 1 } else { paramOffset = 0 } // Method must be exported. if method.PkgPath != "" { continue } // Method needs four ins: receiver, *http.Request, *args, *reply. if mtype.NumIn() != 3+paramOffset { continue } // If the service methods accept an HTTP request pointer if passReq { // First argument must be a pointer and must be http.Request. reqType := mtype.In(1) if reqType.Kind() != reflect.Ptr || reqType.Elem() != typeOfRequest { continue } } // Next argument must be a pointer and must be exported. args := mtype.In(1 + paramOffset) if args.Kind() != reflect.Ptr || !isExportedOrBuiltin(args) { continue } // Next argument must be a pointer and must be exported. reply := mtype.In(2 + paramOffset) if reply.Kind() != reflect.Ptr || !isExportedOrBuiltin(reply) { continue } // Method needs one out: error. if mtype.NumOut() != 1 { continue } if returnType := mtype.Out(0); returnType != typeOfError { continue } s.methods[method.Name] = &serviceMethod{ method: method, argsType: args.Elem(), replyType: reply.Elem(), } } if len(s.methods) == 0 { return fmt.Errorf("rpc: %q has no exported methods of suitable type", s.name) } // Add to the map. m.mutex.Lock() defer m.mutex.Unlock() if m.services == nil { m.services = make(map[string]*service) } else if _, ok := m.services[s.name]; ok { return fmt.Errorf("rpc: service already defined: %q", s.name) } m.services[s.name] = s return nil }
[ "func", "(", "m", "*", "serviceMap", ")", "register", "(", "rcvr", "interface", "{", "}", ",", "name", "string", ",", "passReq", "bool", ")", "error", "{", "// Setup service.", "s", ":=", "&", "service", "{", "name", ":", "name", ",", "rcvr", ":", "reflect", ".", "ValueOf", "(", "rcvr", ")", ",", "rcvrType", ":", "reflect", ".", "TypeOf", "(", "rcvr", ")", ",", "methods", ":", "make", "(", "map", "[", "string", "]", "*", "serviceMethod", ")", ",", "passReq", ":", "passReq", ",", "}", "\n", "if", "name", "==", "\"", "\"", "{", "s", ".", "name", "=", "reflect", ".", "Indirect", "(", "s", ".", "rcvr", ")", ".", "Type", "(", ")", ".", "Name", "(", ")", "\n", "if", "!", "isExported", "(", "s", ".", "name", ")", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "s", ".", "name", ")", "\n", "}", "\n", "}", "\n", "if", "s", ".", "name", "==", "\"", "\"", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "s", ".", "rcvrType", ".", "String", "(", ")", ")", "\n", "}", "\n", "// Setup methods.", "for", "i", ":=", "0", ";", "i", "<", "s", ".", "rcvrType", ".", "NumMethod", "(", ")", ";", "i", "++", "{", "method", ":=", "s", ".", "rcvrType", ".", "Method", "(", "i", ")", "\n", "mtype", ":=", "method", ".", "Type", "\n\n", "// offset the parameter indexes by one if the", "// service methods accept an HTTP request pointer", "var", "paramOffset", "int", "\n", "if", "passReq", "{", "paramOffset", "=", "1", "\n", "}", "else", "{", "paramOffset", "=", "0", "\n", "}", "\n\n", "// Method must be exported.", "if", "method", ".", "PkgPath", "!=", "\"", "\"", "{", "continue", "\n", "}", "\n", "// Method needs four ins: receiver, *http.Request, *args, *reply.", "if", "mtype", ".", "NumIn", "(", ")", "!=", "3", "+", "paramOffset", "{", "continue", "\n", "}", "\n\n", "// If the service methods accept an HTTP request pointer", "if", "passReq", "{", "// First argument must be a pointer and must be http.Request.", "reqType", ":=", "mtype", ".", "In", "(", "1", ")", "\n", "if", "reqType", ".", "Kind", "(", ")", "!=", "reflect", ".", "Ptr", "||", "reqType", ".", "Elem", "(", ")", "!=", "typeOfRequest", "{", "continue", "\n", "}", "\n", "}", "\n", "// Next argument must be a pointer and must be exported.", "args", ":=", "mtype", ".", "In", "(", "1", "+", "paramOffset", ")", "\n", "if", "args", ".", "Kind", "(", ")", "!=", "reflect", ".", "Ptr", "||", "!", "isExportedOrBuiltin", "(", "args", ")", "{", "continue", "\n", "}", "\n", "// Next argument must be a pointer and must be exported.", "reply", ":=", "mtype", ".", "In", "(", "2", "+", "paramOffset", ")", "\n", "if", "reply", ".", "Kind", "(", ")", "!=", "reflect", ".", "Ptr", "||", "!", "isExportedOrBuiltin", "(", "reply", ")", "{", "continue", "\n", "}", "\n", "// Method needs one out: error.", "if", "mtype", ".", "NumOut", "(", ")", "!=", "1", "{", "continue", "\n", "}", "\n", "if", "returnType", ":=", "mtype", ".", "Out", "(", "0", ")", ";", "returnType", "!=", "typeOfError", "{", "continue", "\n", "}", "\n", "s", ".", "methods", "[", "method", ".", "Name", "]", "=", "&", "serviceMethod", "{", "method", ":", "method", ",", "argsType", ":", "args", ".", "Elem", "(", ")", ",", "replyType", ":", "reply", ".", "Elem", "(", ")", ",", "}", "\n", "}", "\n", "if", "len", "(", "s", ".", "methods", ")", "==", "0", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "s", ".", "name", ")", "\n", "}", "\n", "// Add to the map.", "m", ".", "mutex", ".", "Lock", "(", ")", "\n", "defer", "m", ".", "mutex", ".", "Unlock", "(", ")", "\n", "if", "m", ".", "services", "==", "nil", "{", "m", ".", "services", "=", "make", "(", "map", "[", "string", "]", "*", "service", ")", "\n", "}", "else", "if", "_", ",", "ok", ":=", "m", ".", "services", "[", "s", ".", "name", "]", ";", "ok", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "s", ".", "name", ")", "\n", "}", "\n", "m", ".", "services", "[", "s", ".", "name", "]", "=", "s", "\n", "return", "nil", "\n", "}" ]
// register adds a new service using reflection to extract its methods.
[ "register", "adds", "a", "new", "service", "using", "reflection", "to", "extract", "its", "methods", "." ]
bffcfa752ad4e523cc8f720afeb5b985ed41ae16
https://github.com/gorilla/rpc/blob/bffcfa752ad4e523cc8f720afeb5b985ed41ae16/map.go#L53-L140
144,239
gorilla/rpc
map.go
get
func (m *serviceMap) get(method string) (*service, *serviceMethod, error) { parts := strings.Split(method, ".") if len(parts) != 2 { err := fmt.Errorf("rpc: service/method request ill-formed: %q", method) return nil, nil, err } m.mutex.Lock() service := m.services[parts[0]] m.mutex.Unlock() if service == nil { err := fmt.Errorf("rpc: can't find service %q", method) return nil, nil, err } serviceMethod := service.methods[parts[1]] if serviceMethod == nil { err := fmt.Errorf("rpc: can't find method %q", method) return nil, nil, err } return service, serviceMethod, nil }
go
func (m *serviceMap) get(method string) (*service, *serviceMethod, error) { parts := strings.Split(method, ".") if len(parts) != 2 { err := fmt.Errorf("rpc: service/method request ill-formed: %q", method) return nil, nil, err } m.mutex.Lock() service := m.services[parts[0]] m.mutex.Unlock() if service == nil { err := fmt.Errorf("rpc: can't find service %q", method) return nil, nil, err } serviceMethod := service.methods[parts[1]] if serviceMethod == nil { err := fmt.Errorf("rpc: can't find method %q", method) return nil, nil, err } return service, serviceMethod, nil }
[ "func", "(", "m", "*", "serviceMap", ")", "get", "(", "method", "string", ")", "(", "*", "service", ",", "*", "serviceMethod", ",", "error", ")", "{", "parts", ":=", "strings", ".", "Split", "(", "method", ",", "\"", "\"", ")", "\n", "if", "len", "(", "parts", ")", "!=", "2", "{", "err", ":=", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "method", ")", "\n", "return", "nil", ",", "nil", ",", "err", "\n", "}", "\n", "m", ".", "mutex", ".", "Lock", "(", ")", "\n", "service", ":=", "m", ".", "services", "[", "parts", "[", "0", "]", "]", "\n", "m", ".", "mutex", ".", "Unlock", "(", ")", "\n", "if", "service", "==", "nil", "{", "err", ":=", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "method", ")", "\n", "return", "nil", ",", "nil", ",", "err", "\n", "}", "\n", "serviceMethod", ":=", "service", ".", "methods", "[", "parts", "[", "1", "]", "]", "\n", "if", "serviceMethod", "==", "nil", "{", "err", ":=", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "method", ")", "\n", "return", "nil", ",", "nil", ",", "err", "\n", "}", "\n", "return", "service", ",", "serviceMethod", ",", "nil", "\n", "}" ]
// get returns a registered service given a method name. // // The method name uses a dotted notation as in "Service.Method".
[ "get", "returns", "a", "registered", "service", "given", "a", "method", "name", ".", "The", "method", "name", "uses", "a", "dotted", "notation", "as", "in", "Service", ".", "Method", "." ]
bffcfa752ad4e523cc8f720afeb5b985ed41ae16
https://github.com/gorilla/rpc/blob/bffcfa752ad4e523cc8f720afeb5b985ed41ae16/map.go#L145-L164
144,240
gorilla/rpc
map.go
isExportedOrBuiltin
func isExportedOrBuiltin(t reflect.Type) bool { for t.Kind() == reflect.Ptr { t = t.Elem() } // PkgPath will be non-empty even for an exported type, // so we need to check the type name as well. return isExported(t.Name()) || t.PkgPath() == "" }
go
func isExportedOrBuiltin(t reflect.Type) bool { for t.Kind() == reflect.Ptr { t = t.Elem() } // PkgPath will be non-empty even for an exported type, // so we need to check the type name as well. return isExported(t.Name()) || t.PkgPath() == "" }
[ "func", "isExportedOrBuiltin", "(", "t", "reflect", ".", "Type", ")", "bool", "{", "for", "t", ".", "Kind", "(", ")", "==", "reflect", ".", "Ptr", "{", "t", "=", "t", ".", "Elem", "(", ")", "\n", "}", "\n", "// PkgPath will be non-empty even for an exported type,", "// so we need to check the type name as well.", "return", "isExported", "(", "t", ".", "Name", "(", ")", ")", "||", "t", ".", "PkgPath", "(", ")", "==", "\"", "\"", "\n", "}" ]
// isExportedOrBuiltin returns true if a type is exported or a builtin.
[ "isExportedOrBuiltin", "returns", "true", "if", "a", "type", "is", "exported", "or", "a", "builtin", "." ]
bffcfa752ad4e523cc8f720afeb5b985ed41ae16
https://github.com/gorilla/rpc/blob/bffcfa752ad4e523cc8f720afeb5b985ed41ae16/map.go#L173-L180
144,241
gorilla/rpc
v2/compression_selector.go
Select
func (*CompressionSelector) Select(r *http.Request) Encoder { encHeader := r.Header.Get("Accept-Encoding") encTypes := strings.FieldsFunc(encHeader, func(r rune) bool { return unicode.IsSpace(r) || r == ',' }) for _, enc := range encTypes { switch enc { case "gzip": return &gzipEncoder{} case "deflate": return &flateEncoder{} } } return DefaultEncoder }
go
func (*CompressionSelector) Select(r *http.Request) Encoder { encHeader := r.Header.Get("Accept-Encoding") encTypes := strings.FieldsFunc(encHeader, func(r rune) bool { return unicode.IsSpace(r) || r == ',' }) for _, enc := range encTypes { switch enc { case "gzip": return &gzipEncoder{} case "deflate": return &flateEncoder{} } } return DefaultEncoder }
[ "func", "(", "*", "CompressionSelector", ")", "Select", "(", "r", "*", "http", ".", "Request", ")", "Encoder", "{", "encHeader", ":=", "r", ".", "Header", ".", "Get", "(", "\"", "\"", ")", "\n", "encTypes", ":=", "strings", ".", "FieldsFunc", "(", "encHeader", ",", "func", "(", "r", "rune", ")", "bool", "{", "return", "unicode", ".", "IsSpace", "(", "r", ")", "||", "r", "==", "','", "\n", "}", ")", "\n\n", "for", "_", ",", "enc", ":=", "range", "encTypes", "{", "switch", "enc", "{", "case", "\"", "\"", ":", "return", "&", "gzipEncoder", "{", "}", "\n", "case", "\"", "\"", ":", "return", "&", "flateEncoder", "{", "}", "\n", "}", "\n", "}", "\n\n", "return", "DefaultEncoder", "\n", "}" ]
// Select method selects the correct compression encoder based on http HEADER.
[ "Select", "method", "selects", "the", "correct", "compression", "encoder", "based", "on", "http", "HEADER", "." ]
bffcfa752ad4e523cc8f720afeb5b985ed41ae16
https://github.com/gorilla/rpc/blob/bffcfa752ad4e523cc8f720afeb5b985ed41ae16/v2/compression_selector.go#L64-L80
144,242
gorilla/rpc
v2/json2/client.go
EncodeClientRequest
func EncodeClientRequest(method string, args interface{}) ([]byte, error) { c := &clientRequest{ Version: "2.0", Method: method, Params: args, Id: uint64(rand.Int63()), } return json.Marshal(c) }
go
func EncodeClientRequest(method string, args interface{}) ([]byte, error) { c := &clientRequest{ Version: "2.0", Method: method, Params: args, Id: uint64(rand.Int63()), } return json.Marshal(c) }
[ "func", "EncodeClientRequest", "(", "method", "string", ",", "args", "interface", "{", "}", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "c", ":=", "&", "clientRequest", "{", "Version", ":", "\"", "\"", ",", "Method", ":", "method", ",", "Params", ":", "args", ",", "Id", ":", "uint64", "(", "rand", ".", "Int63", "(", ")", ")", ",", "}", "\n", "return", "json", ".", "Marshal", "(", "c", ")", "\n", "}" ]
// EncodeClientRequest encodes parameters for a JSON-RPC client request.
[ "EncodeClientRequest", "encodes", "parameters", "for", "a", "JSON", "-", "RPC", "client", "request", "." ]
bffcfa752ad4e523cc8f720afeb5b985ed41ae16
https://github.com/gorilla/rpc/blob/bffcfa752ad4e523cc8f720afeb5b985ed41ae16/v2/json2/client.go#L42-L50
144,243
gorilla/rpc
v2/protorpc/server.go
ReadRequest
func (c *CodecRequest) ReadRequest(args interface{}) error { if c.err == nil { if c.request.Params != nil { c.err = json.Unmarshal(*c.request.Params, args) } else { c.err = errors.New("rpc: method request ill-formed: missing params field") } } return c.err }
go
func (c *CodecRequest) ReadRequest(args interface{}) error { if c.err == nil { if c.request.Params != nil { c.err = json.Unmarshal(*c.request.Params, args) } else { c.err = errors.New("rpc: method request ill-formed: missing params field") } } return c.err }
[ "func", "(", "c", "*", "CodecRequest", ")", "ReadRequest", "(", "args", "interface", "{", "}", ")", "error", "{", "if", "c", ".", "err", "==", "nil", "{", "if", "c", ".", "request", ".", "Params", "!=", "nil", "{", "c", ".", "err", "=", "json", ".", "Unmarshal", "(", "*", "c", ".", "request", ".", "Params", ",", "args", ")", "\n", "}", "else", "{", "c", ".", "err", "=", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "}", "\n", "return", "c", ".", "err", "\n", "}" ]
// ReadRequest fills the request object for the RPC method.
[ "ReadRequest", "fills", "the", "request", "object", "for", "the", "RPC", "method", "." ]
bffcfa752ad4e523cc8f720afeb5b985ed41ae16
https://github.com/gorilla/rpc/blob/bffcfa752ad4e523cc8f720afeb5b985ed41ae16/v2/protorpc/server.go#L106-L115
144,244
gorilla/rpc
v2/protorpc/server.go
WriteResponse
func (c *CodecRequest) WriteResponse(w http.ResponseWriter, reply interface{}) { res := &serverResponse{ Result: reply, Error: &null, Id: c.request.Id, } c.writeServerResponse(w, 200, res) }
go
func (c *CodecRequest) WriteResponse(w http.ResponseWriter, reply interface{}) { res := &serverResponse{ Result: reply, Error: &null, Id: c.request.Id, } c.writeServerResponse(w, 200, res) }
[ "func", "(", "c", "*", "CodecRequest", ")", "WriteResponse", "(", "w", "http", ".", "ResponseWriter", ",", "reply", "interface", "{", "}", ")", "{", "res", ":=", "&", "serverResponse", "{", "Result", ":", "reply", ",", "Error", ":", "&", "null", ",", "Id", ":", "c", ".", "request", ".", "Id", ",", "}", "\n", "c", ".", "writeServerResponse", "(", "w", ",", "200", ",", "res", ")", "\n", "}" ]
// WriteResponse encodes the response and writes it to the ResponseWriter.
[ "WriteResponse", "encodes", "the", "response", "and", "writes", "it", "to", "the", "ResponseWriter", "." ]
bffcfa752ad4e523cc8f720afeb5b985ed41ae16
https://github.com/gorilla/rpc/blob/bffcfa752ad4e523cc8f720afeb5b985ed41ae16/v2/protorpc/server.go#L118-L125
144,245
gorilla/rpc
v2/json2/server.go
NewCustomCodecWithErrorMapper
func NewCustomCodecWithErrorMapper(encSel rpc.EncoderSelector, errorMapper func(error) error) *Codec { return &Codec{ encSel: encSel, errorMapper: errorMapper, } }
go
func NewCustomCodecWithErrorMapper(encSel rpc.EncoderSelector, errorMapper func(error) error) *Codec { return &Codec{ encSel: encSel, errorMapper: errorMapper, } }
[ "func", "NewCustomCodecWithErrorMapper", "(", "encSel", "rpc", ".", "EncoderSelector", ",", "errorMapper", "func", "(", "error", ")", "error", ")", "*", "Codec", "{", "return", "&", "Codec", "{", "encSel", ":", "encSel", ",", "errorMapper", ":", "errorMapper", ",", "}", "\n", "}" ]
// NewCustomCodecWithErrorMapper returns a new JSON Codec based on the passed encoder selector // and also accepts an errorMapper function. // The errorMapper function will be called if the Service implementation returns an error, with that // error as a param, replacing it by the value returned by this function. This function is intended // to decouple your service implementation from the codec itself, making possible to return abstract // errors in your service, and then mapping them here to the JSON-RPC error codes.
[ "NewCustomCodecWithErrorMapper", "returns", "a", "new", "JSON", "Codec", "based", "on", "the", "passed", "encoder", "selector", "and", "also", "accepts", "an", "errorMapper", "function", ".", "The", "errorMapper", "function", "will", "be", "called", "if", "the", "Service", "implementation", "returns", "an", "error", "with", "that", "error", "as", "a", "param", "replacing", "it", "by", "the", "value", "returned", "by", "this", "function", ".", "This", "function", "is", "intended", "to", "decouple", "your", "service", "implementation", "from", "the", "codec", "itself", "making", "possible", "to", "return", "abstract", "errors", "in", "your", "service", "and", "then", "mapping", "them", "here", "to", "the", "JSON", "-", "RPC", "error", "codes", "." ]
bffcfa752ad4e523cc8f720afeb5b985ed41ae16
https://github.com/gorilla/rpc/blob/bffcfa752ad4e523cc8f720afeb5b985ed41ae16/v2/json2/server.go#L73-L78
144,246
brocaar/lorawan
phypayload.go
MarshalBinary
func (k AES128Key) MarshalBinary() ([]byte, error) { b := make([]byte, len(k)) for i, v := range k { // little endian b[len(k)-i-1] = v } return b, nil }
go
func (k AES128Key) MarshalBinary() ([]byte, error) { b := make([]byte, len(k)) for i, v := range k { // little endian b[len(k)-i-1] = v } return b, nil }
[ "func", "(", "k", "AES128Key", ")", "MarshalBinary", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "b", ":=", "make", "(", "[", "]", "byte", ",", "len", "(", "k", ")", ")", "\n", "for", "i", ",", "v", ":=", "range", "k", "{", "// little endian", "b", "[", "len", "(", "k", ")", "-", "i", "-", "1", "]", "=", "v", "\n", "}", "\n", "return", "b", ",", "nil", "\n", "}" ]
// MarshalBinary encodes the key to a slice of bytes.
[ "MarshalBinary", "encodes", "the", "key", "to", "a", "slice", "of", "bytes", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/phypayload.go#L107-L114
144,247
brocaar/lorawan
phypayload.go
UnmarshalBinary
func (k *AES128Key) UnmarshalBinary(data []byte) error { if len(data) != len(k) { return fmt.Errorf("lorawan: %d bytes of data are expected", len(k)) } for i, v := range data { // little endian k[len(k)-i-1] = v } return nil }
go
func (k *AES128Key) UnmarshalBinary(data []byte) error { if len(data) != len(k) { return fmt.Errorf("lorawan: %d bytes of data are expected", len(k)) } for i, v := range data { // little endian k[len(k)-i-1] = v } return nil }
[ "func", "(", "k", "*", "AES128Key", ")", "UnmarshalBinary", "(", "data", "[", "]", "byte", ")", "error", "{", "if", "len", "(", "data", ")", "!=", "len", "(", "k", ")", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "len", "(", "k", ")", ")", "\n", "}", "\n\n", "for", "i", ",", "v", ":=", "range", "data", "{", "// little endian", "k", "[", "len", "(", "k", ")", "-", "i", "-", "1", "]", "=", "v", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// UnmarshalBinary decodes the key from a slice of bytes.
[ "UnmarshalBinary", "decodes", "the", "key", "from", "a", "slice", "of", "bytes", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/phypayload.go#L117-L128
144,248
brocaar/lorawan
phypayload.go
SetUplinkDataMIC
func (p *PHYPayload) SetUplinkDataMIC(macVersion MACVersion, confFCnt uint32, txDR, txCh uint8, fNwkSIntKey, sNwkSIntKey AES128Key) error { mic, err := p.calculateUplinkDataMIC(macVersion, confFCnt, txDR, txCh, fNwkSIntKey, sNwkSIntKey) if err != nil { return err } p.MIC = mic return nil }
go
func (p *PHYPayload) SetUplinkDataMIC(macVersion MACVersion, confFCnt uint32, txDR, txCh uint8, fNwkSIntKey, sNwkSIntKey AES128Key) error { mic, err := p.calculateUplinkDataMIC(macVersion, confFCnt, txDR, txCh, fNwkSIntKey, sNwkSIntKey) if err != nil { return err } p.MIC = mic return nil }
[ "func", "(", "p", "*", "PHYPayload", ")", "SetUplinkDataMIC", "(", "macVersion", "MACVersion", ",", "confFCnt", "uint32", ",", "txDR", ",", "txCh", "uint8", ",", "fNwkSIntKey", ",", "sNwkSIntKey", "AES128Key", ")", "error", "{", "mic", ",", "err", ":=", "p", ".", "calculateUplinkDataMIC", "(", "macVersion", ",", "confFCnt", ",", "txDR", ",", "txCh", ",", "fNwkSIntKey", ",", "sNwkSIntKey", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "p", ".", "MIC", "=", "mic", "\n", "return", "nil", "\n", "}" ]
// SetUplinkDataMIC calculates and sets the MIC field for uplink data frames. // The confirmed frame-counter, TX data-rate TX channel index and SNwkSIntKey // are only required for LoRaWAN 1.1 and can be left blank otherwise.
[ "SetUplinkDataMIC", "calculates", "and", "sets", "the", "MIC", "field", "for", "uplink", "data", "frames", ".", "The", "confirmed", "frame", "-", "counter", "TX", "data", "-", "rate", "TX", "channel", "index", "and", "SNwkSIntKey", "are", "only", "required", "for", "LoRaWAN", "1", ".", "1", "and", "can", "be", "left", "blank", "otherwise", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/phypayload.go#L174-L181
144,249
brocaar/lorawan
phypayload.go
SetDownlinkDataMIC
func (p *PHYPayload) SetDownlinkDataMIC(macVersion MACVersion, confFCnt uint32, sNwkSIntKey AES128Key) error { mic, err := p.calculateDownlinkDataMIC(macVersion, confFCnt, sNwkSIntKey) if err != nil { return err } p.MIC = mic return nil }
go
func (p *PHYPayload) SetDownlinkDataMIC(macVersion MACVersion, confFCnt uint32, sNwkSIntKey AES128Key) error { mic, err := p.calculateDownlinkDataMIC(macVersion, confFCnt, sNwkSIntKey) if err != nil { return err } p.MIC = mic return nil }
[ "func", "(", "p", "*", "PHYPayload", ")", "SetDownlinkDataMIC", "(", "macVersion", "MACVersion", ",", "confFCnt", "uint32", ",", "sNwkSIntKey", "AES128Key", ")", "error", "{", "mic", ",", "err", ":=", "p", ".", "calculateDownlinkDataMIC", "(", "macVersion", ",", "confFCnt", ",", "sNwkSIntKey", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "p", ".", "MIC", "=", "mic", "\n", "return", "nil", "\n", "}" ]
// SetDownlinkDataMIC calculates and sets the MIC field for downlink data frames. // The confirmed frame-counter and is only required for LoRaWAN 1.1 and can be // left blank otherwise.
[ "SetDownlinkDataMIC", "calculates", "and", "sets", "the", "MIC", "field", "for", "downlink", "data", "frames", ".", "The", "confirmed", "frame", "-", "counter", "and", "is", "only", "required", "for", "LoRaWAN", "1", ".", "1", "and", "can", "be", "left", "blank", "otherwise", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/phypayload.go#L200-L207
144,250
brocaar/lorawan
phypayload.go
ValidateDownlinkDataMIC
func (p PHYPayload) ValidateDownlinkDataMIC(macVersion MACVersion, confFCnt uint32, sNwkSIntKey AES128Key) (bool, error) { mic, err := p.calculateDownlinkDataMIC(macVersion, confFCnt, sNwkSIntKey) if err != nil { return false, err } return p.MIC == mic, nil }
go
func (p PHYPayload) ValidateDownlinkDataMIC(macVersion MACVersion, confFCnt uint32, sNwkSIntKey AES128Key) (bool, error) { mic, err := p.calculateDownlinkDataMIC(macVersion, confFCnt, sNwkSIntKey) if err != nil { return false, err } return p.MIC == mic, nil }
[ "func", "(", "p", "PHYPayload", ")", "ValidateDownlinkDataMIC", "(", "macVersion", "MACVersion", ",", "confFCnt", "uint32", ",", "sNwkSIntKey", "AES128Key", ")", "(", "bool", ",", "error", ")", "{", "mic", ",", "err", ":=", "p", ".", "calculateDownlinkDataMIC", "(", "macVersion", ",", "confFCnt", ",", "sNwkSIntKey", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "\n", "return", "p", ".", "MIC", "==", "mic", ",", "nil", "\n", "}" ]
// ValidateDownlinkDataMIC validates the MIC of a downlink data frame. // In order to validate the MIC, the FCnt value must first be set to the // full 32 bit frame-counter value, as only the 16 least-significant bits // are transmitted. // The confirmed frame-counter and is only required for LoRaWAN 1.1 and can be // left blank otherwise.
[ "ValidateDownlinkDataMIC", "validates", "the", "MIC", "of", "a", "downlink", "data", "frame", ".", "In", "order", "to", "validate", "the", "MIC", "the", "FCnt", "value", "must", "first", "be", "set", "to", "the", "full", "32", "bit", "frame", "-", "counter", "value", "as", "only", "the", "16", "least", "-", "significant", "bits", "are", "transmitted", ".", "The", "confirmed", "frame", "-", "counter", "and", "is", "only", "required", "for", "LoRaWAN", "1", ".", "1", "and", "can", "be", "left", "blank", "otherwise", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/phypayload.go#L215-L221
144,251
brocaar/lorawan
phypayload.go
SetUplinkJoinMIC
func (p *PHYPayload) SetUplinkJoinMIC(key AES128Key) error { mic, err := p.calculateUplinkJoinMIC(key) if err != nil { return err } p.MIC = mic return nil }
go
func (p *PHYPayload) SetUplinkJoinMIC(key AES128Key) error { mic, err := p.calculateUplinkJoinMIC(key) if err != nil { return err } p.MIC = mic return nil }
[ "func", "(", "p", "*", "PHYPayload", ")", "SetUplinkJoinMIC", "(", "key", "AES128Key", ")", "error", "{", "mic", ",", "err", ":=", "p", ".", "calculateUplinkJoinMIC", "(", "key", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "p", ".", "MIC", "=", "mic", "\n", "return", "nil", "\n", "}" ]
// SetUplinkJoinMIC calculates and sets the MIC field for uplink join requests.
[ "SetUplinkJoinMIC", "calculates", "and", "sets", "the", "MIC", "field", "for", "uplink", "join", "requests", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/phypayload.go#L224-L231
144,252
brocaar/lorawan
phypayload.go
ValidateUplinkJoinMIC
func (p PHYPayload) ValidateUplinkJoinMIC(key AES128Key) (bool, error) { mic, err := p.calculateUplinkJoinMIC(key) if err != nil { return false, err } return p.MIC == mic, nil }
go
func (p PHYPayload) ValidateUplinkJoinMIC(key AES128Key) (bool, error) { mic, err := p.calculateUplinkJoinMIC(key) if err != nil { return false, err } return p.MIC == mic, nil }
[ "func", "(", "p", "PHYPayload", ")", "ValidateUplinkJoinMIC", "(", "key", "AES128Key", ")", "(", "bool", ",", "error", ")", "{", "mic", ",", "err", ":=", "p", ".", "calculateUplinkJoinMIC", "(", "key", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "\n", "return", "p", ".", "MIC", "==", "mic", ",", "nil", "\n", "}" ]
// ValidateUplinkJoinMIC validates the MIC of an uplink join request.
[ "ValidateUplinkJoinMIC", "validates", "the", "MIC", "of", "an", "uplink", "join", "request", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/phypayload.go#L234-L240
144,253
brocaar/lorawan
phypayload.go
SetDownlinkJoinMIC
func (p *PHYPayload) SetDownlinkJoinMIC(joinReqType JoinType, joinEUI EUI64, devNonce DevNonce, key AES128Key) error { mic, err := p.calculateDownlinkJoinMIC(joinReqType, joinEUI, devNonce, key) if err != nil { return err } p.MIC = mic return nil }
go
func (p *PHYPayload) SetDownlinkJoinMIC(joinReqType JoinType, joinEUI EUI64, devNonce DevNonce, key AES128Key) error { mic, err := p.calculateDownlinkJoinMIC(joinReqType, joinEUI, devNonce, key) if err != nil { return err } p.MIC = mic return nil }
[ "func", "(", "p", "*", "PHYPayload", ")", "SetDownlinkJoinMIC", "(", "joinReqType", "JoinType", ",", "joinEUI", "EUI64", ",", "devNonce", "DevNonce", ",", "key", "AES128Key", ")", "error", "{", "mic", ",", "err", ":=", "p", ".", "calculateDownlinkJoinMIC", "(", "joinReqType", ",", "joinEUI", ",", "devNonce", ",", "key", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "p", ".", "MIC", "=", "mic", "\n", "return", "nil", "\n", "}" ]
// SetDownlinkJoinMIC calculates and sets the MIC field for downlink join requests.
[ "SetDownlinkJoinMIC", "calculates", "and", "sets", "the", "MIC", "field", "for", "downlink", "join", "requests", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/phypayload.go#L243-L250
144,254
brocaar/lorawan
phypayload.go
EncryptFOpts
func (p *PHYPayload) EncryptFOpts(nwkSEncKey AES128Key) error { macPL, ok := p.MACPayload.(*MACPayload) if !ok { return errors.New("lorawan: MACPayload must be of type *MACPayload") } // nothing to encrypt if len(macPL.FHDR.FOpts) == 0 { return nil } var macB []byte for _, mac := range macPL.FHDR.FOpts { b, err := mac.MarshalBinary() if err != nil { return err } macB = append(macB, b...) } // aFCntDown is used on downlink when FPort > 1 var aFCntDown bool if !p.isUplink() && macPL.FPort != nil && *macPL.FPort > 0 { aFCntDown = true } data, err := EncryptFOpts(nwkSEncKey, aFCntDown, p.isUplink(), macPL.FHDR.DevAddr, macPL.FHDR.FCnt, macB) if err != nil { return err } macPL.FHDR.FOpts = []Payload{ &DataPayload{Bytes: data}, } return nil }
go
func (p *PHYPayload) EncryptFOpts(nwkSEncKey AES128Key) error { macPL, ok := p.MACPayload.(*MACPayload) if !ok { return errors.New("lorawan: MACPayload must be of type *MACPayload") } // nothing to encrypt if len(macPL.FHDR.FOpts) == 0 { return nil } var macB []byte for _, mac := range macPL.FHDR.FOpts { b, err := mac.MarshalBinary() if err != nil { return err } macB = append(macB, b...) } // aFCntDown is used on downlink when FPort > 1 var aFCntDown bool if !p.isUplink() && macPL.FPort != nil && *macPL.FPort > 0 { aFCntDown = true } data, err := EncryptFOpts(nwkSEncKey, aFCntDown, p.isUplink(), macPL.FHDR.DevAddr, macPL.FHDR.FCnt, macB) if err != nil { return err } macPL.FHDR.FOpts = []Payload{ &DataPayload{Bytes: data}, } return nil }
[ "func", "(", "p", "*", "PHYPayload", ")", "EncryptFOpts", "(", "nwkSEncKey", "AES128Key", ")", "error", "{", "macPL", ",", "ok", ":=", "p", ".", "MACPayload", ".", "(", "*", "MACPayload", ")", "\n", "if", "!", "ok", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "// nothing to encrypt", "if", "len", "(", "macPL", ".", "FHDR", ".", "FOpts", ")", "==", "0", "{", "return", "nil", "\n", "}", "\n\n", "var", "macB", "[", "]", "byte", "\n", "for", "_", ",", "mac", ":=", "range", "macPL", ".", "FHDR", ".", "FOpts", "{", "b", ",", "err", ":=", "mac", ".", "MarshalBinary", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "macB", "=", "append", "(", "macB", ",", "b", "...", ")", "\n", "}", "\n\n", "// aFCntDown is used on downlink when FPort > 1", "var", "aFCntDown", "bool", "\n", "if", "!", "p", ".", "isUplink", "(", ")", "&&", "macPL", ".", "FPort", "!=", "nil", "&&", "*", "macPL", ".", "FPort", ">", "0", "{", "aFCntDown", "=", "true", "\n", "}", "\n\n", "data", ",", "err", ":=", "EncryptFOpts", "(", "nwkSEncKey", ",", "aFCntDown", ",", "p", ".", "isUplink", "(", ")", ",", "macPL", ".", "FHDR", ".", "DevAddr", ",", "macPL", ".", "FHDR", ".", "FCnt", ",", "macB", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "macPL", ".", "FHDR", ".", "FOpts", "=", "[", "]", "Payload", "{", "&", "DataPayload", "{", "Bytes", ":", "data", "}", ",", "}", "\n\n", "return", "nil", "\n", "}" ]
// EncryptFOpts encrypts the FOpts with the given key.
[ "EncryptFOpts", "encrypts", "the", "FOpts", "with", "the", "given", "key", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/phypayload.go#L340-L376
144,255
brocaar/lorawan
phypayload.go
DecryptFOpts
func (p *PHYPayload) DecryptFOpts(nwkSEncKey AES128Key) error { if err := p.EncryptFOpts(nwkSEncKey); err != nil { return nil } return p.DecodeFOptsToMACCommands() }
go
func (p *PHYPayload) DecryptFOpts(nwkSEncKey AES128Key) error { if err := p.EncryptFOpts(nwkSEncKey); err != nil { return nil } return p.DecodeFOptsToMACCommands() }
[ "func", "(", "p", "*", "PHYPayload", ")", "DecryptFOpts", "(", "nwkSEncKey", "AES128Key", ")", "error", "{", "if", "err", ":=", "p", ".", "EncryptFOpts", "(", "nwkSEncKey", ")", ";", "err", "!=", "nil", "{", "return", "nil", "\n", "}", "\n\n", "return", "p", ".", "DecodeFOptsToMACCommands", "(", ")", "\n", "}" ]
// DecryptFOpts decrypts the FOpts payload and decodes it into mac-command // structures.
[ "DecryptFOpts", "decrypts", "the", "FOpts", "payload", "and", "decodes", "it", "into", "mac", "-", "command", "structures", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/phypayload.go#L380-L386
144,256
brocaar/lorawan
phypayload.go
EncryptFRMPayload
func (p *PHYPayload) EncryptFRMPayload(key AES128Key) error { macPL, ok := p.MACPayload.(*MACPayload) if !ok { return errors.New("lorawan: MACPayload must be of type *MACPayload") } // nothing to encrypt if len(macPL.FRMPayload) == 0 { return nil } data, err := macPL.marshalPayload() if err != nil { return err } data, err = EncryptFRMPayload(key, p.isUplink(), macPL.FHDR.DevAddr, macPL.FHDR.FCnt, data) if err != nil { return err } // store the encrypted data in a DataPayload macPL.FRMPayload = []Payload{&DataPayload{Bytes: data}} return nil }
go
func (p *PHYPayload) EncryptFRMPayload(key AES128Key) error { macPL, ok := p.MACPayload.(*MACPayload) if !ok { return errors.New("lorawan: MACPayload must be of type *MACPayload") } // nothing to encrypt if len(macPL.FRMPayload) == 0 { return nil } data, err := macPL.marshalPayload() if err != nil { return err } data, err = EncryptFRMPayload(key, p.isUplink(), macPL.FHDR.DevAddr, macPL.FHDR.FCnt, data) if err != nil { return err } // store the encrypted data in a DataPayload macPL.FRMPayload = []Payload{&DataPayload{Bytes: data}} return nil }
[ "func", "(", "p", "*", "PHYPayload", ")", "EncryptFRMPayload", "(", "key", "AES128Key", ")", "error", "{", "macPL", ",", "ok", ":=", "p", ".", "MACPayload", ".", "(", "*", "MACPayload", ")", "\n", "if", "!", "ok", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "// nothing to encrypt", "if", "len", "(", "macPL", ".", "FRMPayload", ")", "==", "0", "{", "return", "nil", "\n", "}", "\n\n", "data", ",", "err", ":=", "macPL", ".", "marshalPayload", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "data", ",", "err", "=", "EncryptFRMPayload", "(", "key", ",", "p", ".", "isUplink", "(", ")", ",", "macPL", ".", "FHDR", ".", "DevAddr", ",", "macPL", ".", "FHDR", ".", "FCnt", ",", "data", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "// store the encrypted data in a DataPayload", "macPL", ".", "FRMPayload", "=", "[", "]", "Payload", "{", "&", "DataPayload", "{", "Bytes", ":", "data", "}", "}", "\n\n", "return", "nil", "\n", "}" ]
// EncryptFRMPayload encrypts the FRMPayload with the given key.
[ "EncryptFRMPayload", "encrypts", "the", "FRMPayload", "with", "the", "given", "key", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/phypayload.go#L389-L414
144,257
brocaar/lorawan
phypayload.go
DecryptFRMPayload
func (p *PHYPayload) DecryptFRMPayload(key AES128Key) error { if err := p.EncryptFRMPayload(key); err != nil { return err } macPL, ok := p.MACPayload.(*MACPayload) if !ok { return errors.New("lorawan: MACPayload must be of type *MACPayload") } // the FRMPayload contains MAC commands, which we need to unmarshal var err error if macPL.FPort != nil && *macPL.FPort == 0 { macPL.FRMPayload, err = decodeDataPayloadToMACCommands(p.isUplink(), macPL.FRMPayload) } return err }
go
func (p *PHYPayload) DecryptFRMPayload(key AES128Key) error { if err := p.EncryptFRMPayload(key); err != nil { return err } macPL, ok := p.MACPayload.(*MACPayload) if !ok { return errors.New("lorawan: MACPayload must be of type *MACPayload") } // the FRMPayload contains MAC commands, which we need to unmarshal var err error if macPL.FPort != nil && *macPL.FPort == 0 { macPL.FRMPayload, err = decodeDataPayloadToMACCommands(p.isUplink(), macPL.FRMPayload) } return err }
[ "func", "(", "p", "*", "PHYPayload", ")", "DecryptFRMPayload", "(", "key", "AES128Key", ")", "error", "{", "if", "err", ":=", "p", ".", "EncryptFRMPayload", "(", "key", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "macPL", ",", "ok", ":=", "p", ".", "MACPayload", ".", "(", "*", "MACPayload", ")", "\n", "if", "!", "ok", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "// the FRMPayload contains MAC commands, which we need to unmarshal", "var", "err", "error", "\n", "if", "macPL", ".", "FPort", "!=", "nil", "&&", "*", "macPL", ".", "FPort", "==", "0", "{", "macPL", ".", "FRMPayload", ",", "err", "=", "decodeDataPayloadToMACCommands", "(", "p", ".", "isUplink", "(", ")", ",", "macPL", ".", "FRMPayload", ")", "\n", "}", "\n\n", "return", "err", "\n", "}" ]
// DecryptFRMPayload decrypts the FRMPayload with the given key.
[ "DecryptFRMPayload", "decrypts", "the", "FRMPayload", "with", "the", "given", "key", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/phypayload.go#L417-L434
144,258
brocaar/lorawan
phypayload.go
MarshalText
func (p PHYPayload) MarshalText() ([]byte, error) { b, err := p.MarshalBinary() if err != nil { return nil, err } return []byte(base64.StdEncoding.EncodeToString(b)), nil }
go
func (p PHYPayload) MarshalText() ([]byte, error) { b, err := p.MarshalBinary() if err != nil { return nil, err } return []byte(base64.StdEncoding.EncodeToString(b)), nil }
[ "func", "(", "p", "PHYPayload", ")", "MarshalText", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "b", ",", "err", ":=", "p", ".", "MarshalBinary", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "[", "]", "byte", "(", "base64", ".", "StdEncoding", ".", "EncodeToString", "(", "b", ")", ")", ",", "nil", "\n", "}" ]
// MarshalText encodes the PHYPayload into base64.
[ "MarshalText", "encodes", "the", "PHYPayload", "into", "base64", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/phypayload.go#L535-L541
144,259
brocaar/lorawan
phypayload.go
UnmarshalText
func (p *PHYPayload) UnmarshalText(text []byte) error { b, err := base64.StdEncoding.DecodeString(string(text)) if err != nil { return err } return p.UnmarshalBinary(b) }
go
func (p *PHYPayload) UnmarshalText(text []byte) error { b, err := base64.StdEncoding.DecodeString(string(text)) if err != nil { return err } return p.UnmarshalBinary(b) }
[ "func", "(", "p", "*", "PHYPayload", ")", "UnmarshalText", "(", "text", "[", "]", "byte", ")", "error", "{", "b", ",", "err", ":=", "base64", ".", "StdEncoding", ".", "DecodeString", "(", "string", "(", "text", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "p", ".", "UnmarshalBinary", "(", "b", ")", "\n", "}" ]
// UnmarshalText decodes the PHYPayload from base64.
[ "UnmarshalText", "decodes", "the", "PHYPayload", "from", "base64", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/phypayload.go#L544-L550
144,260
brocaar/lorawan
phypayload.go
MarshalJSON
func (p PHYPayload) MarshalJSON() ([]byte, error) { type phyAlias PHYPayload return json.Marshal(phyAlias(p)) }
go
func (p PHYPayload) MarshalJSON() ([]byte, error) { type phyAlias PHYPayload return json.Marshal(phyAlias(p)) }
[ "func", "(", "p", "PHYPayload", ")", "MarshalJSON", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "type", "phyAlias", "PHYPayload", "\n", "return", "json", ".", "Marshal", "(", "phyAlias", "(", "p", ")", ")", "\n", "}" ]
// MarshalJSON encodes the PHYPayload into JSON.
[ "MarshalJSON", "encodes", "the", "PHYPayload", "into", "JSON", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/phypayload.go#L553-L556
144,261
brocaar/lorawan
applayer/multicastsetup/multicastsetup.go
GetCommandPayload
func GetCommandPayload(uplink bool, c CID) (CommandPayload, error) { v, ok := commandPayloadRegistry[uplink][c] if !ok { return nil, ErrNoPayloadForCID } return v(), nil }
go
func GetCommandPayload(uplink bool, c CID) (CommandPayload, error) { v, ok := commandPayloadRegistry[uplink][c] if !ok { return nil, ErrNoPayloadForCID } return v(), nil }
[ "func", "GetCommandPayload", "(", "uplink", "bool", ",", "c", "CID", ")", "(", "CommandPayload", ",", "error", ")", "{", "v", ",", "ok", ":=", "commandPayloadRegistry", "[", "uplink", "]", "[", "c", "]", "\n", "if", "!", "ok", "{", "return", "nil", ",", "ErrNoPayloadForCID", "\n", "}", "\n\n", "return", "v", "(", ")", ",", "nil", "\n", "}" ]
// GetCommandPayload returns a new CommandPayload for the given CID.
[ "GetCommandPayload", "returns", "a", "new", "CommandPayload", "for", "the", "given", "CID", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/applayer/multicastsetup/multicastsetup.go#L61-L68
144,262
brocaar/lorawan
applayer/multicastsetup/multicastsetup.go
MarshalBinary
func (c Command) MarshalBinary() ([]byte, error) { b := []byte{byte(c.CID)} if c.Payload != nil { p, err := c.Payload.MarshalBinary() if err != nil { return nil, err } b = append(b, p...) } return b, nil }
go
func (c Command) MarshalBinary() ([]byte, error) { b := []byte{byte(c.CID)} if c.Payload != nil { p, err := c.Payload.MarshalBinary() if err != nil { return nil, err } b = append(b, p...) } return b, nil }
[ "func", "(", "c", "Command", ")", "MarshalBinary", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "b", ":=", "[", "]", "byte", "{", "byte", "(", "c", ".", "CID", ")", "}", "\n\n", "if", "c", ".", "Payload", "!=", "nil", "{", "p", ",", "err", ":=", "c", ".", "Payload", ".", "MarshalBinary", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "b", "=", "append", "(", "b", ",", "p", "...", ")", "\n", "}", "\n\n", "return", "b", ",", "nil", "\n", "}" ]
// MarshalBinary encodes the command to a slice of bytes.
[ "MarshalBinary", "encodes", "the", "command", "to", "a", "slice", "of", "bytes", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/applayer/multicastsetup/multicastsetup.go#L84-L96
144,263
brocaar/lorawan
applayer/multicastsetup/multicastsetup.go
UnmarshalBinary
func (c *Command) UnmarshalBinary(uplink bool, data []byte) error { if len(data) == 0 { return errors.New("lorawan/applayer/multicastsetup: at least 1 byte is expected") } c.CID = CID(data[0]) p, err := GetCommandPayload(uplink, c.CID) if err != nil { if err == ErrNoPayloadForCID { return nil } return err } c.Payload = p if err := c.Payload.UnmarshalBinary(data[1:]); err != nil { return err } return nil }
go
func (c *Command) UnmarshalBinary(uplink bool, data []byte) error { if len(data) == 0 { return errors.New("lorawan/applayer/multicastsetup: at least 1 byte is expected") } c.CID = CID(data[0]) p, err := GetCommandPayload(uplink, c.CID) if err != nil { if err == ErrNoPayloadForCID { return nil } return err } c.Payload = p if err := c.Payload.UnmarshalBinary(data[1:]); err != nil { return err } return nil }
[ "func", "(", "c", "*", "Command", ")", "UnmarshalBinary", "(", "uplink", "bool", ",", "data", "[", "]", "byte", ")", "error", "{", "if", "len", "(", "data", ")", "==", "0", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "c", ".", "CID", "=", "CID", "(", "data", "[", "0", "]", ")", "\n\n", "p", ",", "err", ":=", "GetCommandPayload", "(", "uplink", ",", "c", ".", "CID", ")", "\n", "if", "err", "!=", "nil", "{", "if", "err", "==", "ErrNoPayloadForCID", "{", "return", "nil", "\n", "}", "\n", "return", "err", "\n", "}", "\n\n", "c", ".", "Payload", "=", "p", "\n", "if", "err", ":=", "c", ".", "Payload", ".", "UnmarshalBinary", "(", "data", "[", "1", ":", "]", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// UnmarshalBinary decodes a slice of bytes into a command.
[ "UnmarshalBinary", "decodes", "a", "slice", "of", "bytes", "into", "a", "command", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/applayer/multicastsetup/multicastsetup.go#L99-L120
144,264
brocaar/lorawan
applayer/multicastsetup/multicastsetup.go
Size
func (c Command) Size() int { if c.Payload != nil { return c.Payload.Size() + 1 } return 1 }
go
func (c Command) Size() int { if c.Payload != nil { return c.Payload.Size() + 1 } return 1 }
[ "func", "(", "c", "Command", ")", "Size", "(", ")", "int", "{", "if", "c", ".", "Payload", "!=", "nil", "{", "return", "c", ".", "Payload", ".", "Size", "(", ")", "+", "1", "\n", "}", "\n", "return", "1", "\n", "}" ]
// Size returns the size of the command in bytes.
[ "Size", "returns", "the", "size", "of", "the", "command", "in", "bytes", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/applayer/multicastsetup/multicastsetup.go#L123-L128
144,265
brocaar/lorawan
applayer/multicastsetup/multicastsetup.go
MarshalBinary
func (c Commands) MarshalBinary() ([]byte, error) { var out []byte for _, cmd := range c { b, err := cmd.MarshalBinary() if err != nil { return nil, err } out = append(out, b...) } return out, nil }
go
func (c Commands) MarshalBinary() ([]byte, error) { var out []byte for _, cmd := range c { b, err := cmd.MarshalBinary() if err != nil { return nil, err } out = append(out, b...) } return out, nil }
[ "func", "(", "c", "Commands", ")", "MarshalBinary", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "var", "out", "[", "]", "byte", "\n\n", "for", "_", ",", "cmd", ":=", "range", "c", "{", "b", ",", "err", ":=", "cmd", ".", "MarshalBinary", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "out", "=", "append", "(", "out", ",", "b", "...", ")", "\n", "}", "\n", "return", "out", ",", "nil", "\n", "}" ]
// MarshalBinary encodes the commands to a slice of bytes.
[ "MarshalBinary", "encodes", "the", "commands", "to", "a", "slice", "of", "bytes", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/applayer/multicastsetup/multicastsetup.go#L134-L145
144,266
brocaar/lorawan
applayer/multicastsetup/multicastsetup.go
UnmarshalBinary
func (c *Commands) UnmarshalBinary(uplink bool, data []byte) error { var i int for i < len(data) { var cmd Command if err := cmd.UnmarshalBinary(uplink, data[i:]); err != nil { return err } i += cmd.Size() *c = append(*c, cmd) } return nil }
go
func (c *Commands) UnmarshalBinary(uplink bool, data []byte) error { var i int for i < len(data) { var cmd Command if err := cmd.UnmarshalBinary(uplink, data[i:]); err != nil { return err } i += cmd.Size() *c = append(*c, cmd) } return nil }
[ "func", "(", "c", "*", "Commands", ")", "UnmarshalBinary", "(", "uplink", "bool", ",", "data", "[", "]", "byte", ")", "error", "{", "var", "i", "int", "\n\n", "for", "i", "<", "len", "(", "data", ")", "{", "var", "cmd", "Command", "\n", "if", "err", ":=", "cmd", ".", "UnmarshalBinary", "(", "uplink", ",", "data", "[", "i", ":", "]", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "i", "+=", "cmd", ".", "Size", "(", ")", "\n", "*", "c", "=", "append", "(", "*", "c", ",", "cmd", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// UnmarshalBinary decodes a slice of bytes into a slice of commands.
[ "UnmarshalBinary", "decodes", "a", "slice", "of", "bytes", "into", "a", "slice", "of", "commands", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/applayer/multicastsetup/multicastsetup.go#L148-L161
144,267
brocaar/lorawan
applayer/multicastsetup/multicastsetup.go
Size
func (p McGroupStatusAnsPayload) Size() int { var ansGroupMaskCount int for _, mask := range p.Status.AnsGroupMask { if mask { ansGroupMaskCount++ } } return 1 + (5 * ansGroupMaskCount) }
go
func (p McGroupStatusAnsPayload) Size() int { var ansGroupMaskCount int for _, mask := range p.Status.AnsGroupMask { if mask { ansGroupMaskCount++ } } return 1 + (5 * ansGroupMaskCount) }
[ "func", "(", "p", "McGroupStatusAnsPayload", ")", "Size", "(", ")", "int", "{", "var", "ansGroupMaskCount", "int", "\n", "for", "_", ",", "mask", ":=", "range", "p", ".", "Status", ".", "AnsGroupMask", "{", "if", "mask", "{", "ansGroupMaskCount", "++", "\n", "}", "\n", "}", "\n\n", "return", "1", "+", "(", "5", "*", "ansGroupMaskCount", ")", "\n", "}" ]
// Size returns the payload size in number of bytes.
[ "Size", "returns", "the", "payload", "size", "in", "number", "of", "bytes", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/applayer/multicastsetup/multicastsetup.go#L251-L260
144,268
brocaar/lorawan
applayer/multicastsetup/keys.go
GetMcKEKey
func GetMcKEKey(mcRootKey lorawan.AES128Key) (lorawan.AES128Key, error) { return getKey(mcRootKey, [16]byte{}) }
go
func GetMcKEKey(mcRootKey lorawan.AES128Key) (lorawan.AES128Key, error) { return getKey(mcRootKey, [16]byte{}) }
[ "func", "GetMcKEKey", "(", "mcRootKey", "lorawan", ".", "AES128Key", ")", "(", "lorawan", ".", "AES128Key", ",", "error", ")", "{", "return", "getKey", "(", "mcRootKey", ",", "[", "16", "]", "byte", "{", "}", ")", "\n", "}" ]
// GetMcKEKey returns the McKEKey given the McRootKey.
[ "GetMcKEKey", "returns", "the", "McKEKey", "given", "the", "McRootKey", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/applayer/multicastsetup/keys.go#L23-L25
144,269
brocaar/lorawan
applayer/multicastsetup/keys.go
GetMcAppSKey
func GetMcAppSKey(mcKey lorawan.AES128Key, mcAddr lorawan.DevAddr) (lorawan.AES128Key, error) { b := [16]byte{0x01} mcAddrB, err := mcAddr.MarshalBinary() if err != nil { return lorawan.AES128Key{}, err } copy(b[1:5], mcAddrB) return getKey(mcKey, b) }
go
func GetMcAppSKey(mcKey lorawan.AES128Key, mcAddr lorawan.DevAddr) (lorawan.AES128Key, error) { b := [16]byte{0x01} mcAddrB, err := mcAddr.MarshalBinary() if err != nil { return lorawan.AES128Key{}, err } copy(b[1:5], mcAddrB) return getKey(mcKey, b) }
[ "func", "GetMcAppSKey", "(", "mcKey", "lorawan", ".", "AES128Key", ",", "mcAddr", "lorawan", ".", "DevAddr", ")", "(", "lorawan", ".", "AES128Key", ",", "error", ")", "{", "b", ":=", "[", "16", "]", "byte", "{", "0x01", "}", "\n\n", "mcAddrB", ",", "err", ":=", "mcAddr", ".", "MarshalBinary", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "lorawan", ".", "AES128Key", "{", "}", ",", "err", "\n", "}", "\n", "copy", "(", "b", "[", "1", ":", "5", "]", ",", "mcAddrB", ")", "\n\n", "return", "getKey", "(", "mcKey", ",", "b", ")", "\n", "}" ]
// GetMcAppSKey returns the McAppSKey given the McKey and McAddr.
[ "GetMcAppSKey", "returns", "the", "McAppSKey", "given", "the", "McKey", "and", "McAddr", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/applayer/multicastsetup/keys.go#L28-L38
144,270
brocaar/lorawan
backend/joinserver/joinserver.go
NewHandler
func NewHandler(config HandlerConfig) (http.Handler, error) { if config.GetDeviceKeysByDevEUIFunc == nil { return nil, errors.New("backend/joinserver: GetDeviceKeysFunc must not be nil") } h := handler{ config: config, log: config.Logger, } if h.log == nil { h.log = &log.Logger{ Out: ioutil.Discard, } } if h.config.GetKEKByLabelFunc == nil { h.log.Warning("backend/joinserver: get kek by label function is not set") h.config.GetKEKByLabelFunc = func(label string) ([]byte, error) { return nil, nil } } if h.config.GetASKEKLabelByDevEUIFunc == nil { h.log.Warning("backend/joinserver: get application-server kek by deveui function is not set") h.config.GetASKEKLabelByDevEUIFunc = func(devEUI lorawan.EUI64) (string, error) { return "", nil } } return &h, nil }
go
func NewHandler(config HandlerConfig) (http.Handler, error) { if config.GetDeviceKeysByDevEUIFunc == nil { return nil, errors.New("backend/joinserver: GetDeviceKeysFunc must not be nil") } h := handler{ config: config, log: config.Logger, } if h.log == nil { h.log = &log.Logger{ Out: ioutil.Discard, } } if h.config.GetKEKByLabelFunc == nil { h.log.Warning("backend/joinserver: get kek by label function is not set") h.config.GetKEKByLabelFunc = func(label string) ([]byte, error) { return nil, nil } } if h.config.GetASKEKLabelByDevEUIFunc == nil { h.log.Warning("backend/joinserver: get application-server kek by deveui function is not set") h.config.GetASKEKLabelByDevEUIFunc = func(devEUI lorawan.EUI64) (string, error) { return "", nil } } return &h, nil }
[ "func", "NewHandler", "(", "config", "HandlerConfig", ")", "(", "http", ".", "Handler", ",", "error", ")", "{", "if", "config", ".", "GetDeviceKeysByDevEUIFunc", "==", "nil", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "h", ":=", "handler", "{", "config", ":", "config", ",", "log", ":", "config", ".", "Logger", ",", "}", "\n\n", "if", "h", ".", "log", "==", "nil", "{", "h", ".", "log", "=", "&", "log", ".", "Logger", "{", "Out", ":", "ioutil", ".", "Discard", ",", "}", "\n", "}", "\n\n", "if", "h", ".", "config", ".", "GetKEKByLabelFunc", "==", "nil", "{", "h", ".", "log", ".", "Warning", "(", "\"", "\"", ")", "\n\n", "h", ".", "config", ".", "GetKEKByLabelFunc", "=", "func", "(", "label", "string", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "return", "nil", ",", "nil", "\n", "}", "\n", "}", "\n\n", "if", "h", ".", "config", ".", "GetASKEKLabelByDevEUIFunc", "==", "nil", "{", "h", ".", "log", ".", "Warning", "(", "\"", "\"", ")", "\n\n", "h", ".", "config", ".", "GetASKEKLabelByDevEUIFunc", "=", "func", "(", "devEUI", "lorawan", ".", "EUI64", ")", "(", "string", ",", "error", ")", "{", "return", "\"", "\"", ",", "nil", "\n", "}", "\n", "}", "\n\n", "return", "&", "h", ",", "nil", "\n", "}" ]
// NewHandler creates a new join-sever handler.
[ "NewHandler", "creates", "a", "new", "join", "-", "sever", "handler", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/backend/joinserver/joinserver.go#L42-L75
144,271
brocaar/lorawan
fhdr.go
NetIDType
func (a DevAddr) NetIDType() int { for i := 0; i < 8; i++ { if a[0]&(0xff<<(byte(7-i))) == 0xff&(0xff<<(byte(8-i))) { return i } } panic("NetIDType bug!") }
go
func (a DevAddr) NetIDType() int { for i := 0; i < 8; i++ { if a[0]&(0xff<<(byte(7-i))) == 0xff&(0xff<<(byte(8-i))) { return i } } panic("NetIDType bug!") }
[ "func", "(", "a", "DevAddr", ")", "NetIDType", "(", ")", "int", "{", "for", "i", ":=", "0", ";", "i", "<", "8", ";", "i", "++", "{", "if", "a", "[", "0", "]", "&", "(", "0xff", "<<", "(", "byte", "(", "7", "-", "i", ")", ")", ")", "==", "0xff", "&", "(", "0xff", "<<", "(", "byte", "(", "8", "-", "i", ")", ")", ")", "{", "return", "i", "\n", "}", "\n", "}", "\n", "panic", "(", "\"", "\"", ")", "\n", "}" ]
// NetIDType returns the NetID type of the DevAddr.
[ "NetIDType", "returns", "the", "NetID", "type", "of", "the", "DevAddr", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/fhdr.go#L14-L21
144,272
brocaar/lorawan
fhdr.go
NwkID
func (a DevAddr) NwkID() []byte { switch a.NetIDType() { case 0: return a.getNwkID(1, 6) case 1: return a.getNwkID(2, 6) case 2: return a.getNwkID(3, 9) case 3: return a.getNwkID(4, 10) case 4: return a.getNwkID(5, 11) case 5: return a.getNwkID(6, 13) case 6: return a.getNwkID(7, 15) case 7: return a.getNwkID(8, 17) default: return nil } }
go
func (a DevAddr) NwkID() []byte { switch a.NetIDType() { case 0: return a.getNwkID(1, 6) case 1: return a.getNwkID(2, 6) case 2: return a.getNwkID(3, 9) case 3: return a.getNwkID(4, 10) case 4: return a.getNwkID(5, 11) case 5: return a.getNwkID(6, 13) case 6: return a.getNwkID(7, 15) case 7: return a.getNwkID(8, 17) default: return nil } }
[ "func", "(", "a", "DevAddr", ")", "NwkID", "(", ")", "[", "]", "byte", "{", "switch", "a", ".", "NetIDType", "(", ")", "{", "case", "0", ":", "return", "a", ".", "getNwkID", "(", "1", ",", "6", ")", "\n", "case", "1", ":", "return", "a", ".", "getNwkID", "(", "2", ",", "6", ")", "\n", "case", "2", ":", "return", "a", ".", "getNwkID", "(", "3", ",", "9", ")", "\n", "case", "3", ":", "return", "a", ".", "getNwkID", "(", "4", ",", "10", ")", "\n", "case", "4", ":", "return", "a", ".", "getNwkID", "(", "5", ",", "11", ")", "\n", "case", "5", ":", "return", "a", ".", "getNwkID", "(", "6", ",", "13", ")", "\n", "case", "6", ":", "return", "a", ".", "getNwkID", "(", "7", ",", "15", ")", "\n", "case", "7", ":", "return", "a", ".", "getNwkID", "(", "8", ",", "17", ")", "\n", "default", ":", "return", "nil", "\n", "}", "\n", "}" ]
// NwkID returns the NwkID bits of the DevAddr.
[ "NwkID", "returns", "the", "NwkID", "bits", "of", "the", "DevAddr", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/fhdr.go#L24-L45
144,273
brocaar/lorawan
fhdr.go
SetAddrPrefix
func (a *DevAddr) SetAddrPrefix(netID NetID) { switch netID.Type() { case 0: a.setAddrPrefix(1, 6, netID) case 1: a.setAddrPrefix(2, 6, netID) case 2: a.setAddrPrefix(3, 9, netID) case 3: a.setAddrPrefix(4, 10, netID) case 4: a.setAddrPrefix(5, 11, netID) case 5: a.setAddrPrefix(6, 13, netID) case 6: a.setAddrPrefix(7, 15, netID) case 7: a.setAddrPrefix(8, 17, netID) } }
go
func (a *DevAddr) SetAddrPrefix(netID NetID) { switch netID.Type() { case 0: a.setAddrPrefix(1, 6, netID) case 1: a.setAddrPrefix(2, 6, netID) case 2: a.setAddrPrefix(3, 9, netID) case 3: a.setAddrPrefix(4, 10, netID) case 4: a.setAddrPrefix(5, 11, netID) case 5: a.setAddrPrefix(6, 13, netID) case 6: a.setAddrPrefix(7, 15, netID) case 7: a.setAddrPrefix(8, 17, netID) } }
[ "func", "(", "a", "*", "DevAddr", ")", "SetAddrPrefix", "(", "netID", "NetID", ")", "{", "switch", "netID", ".", "Type", "(", ")", "{", "case", "0", ":", "a", ".", "setAddrPrefix", "(", "1", ",", "6", ",", "netID", ")", "\n", "case", "1", ":", "a", ".", "setAddrPrefix", "(", "2", ",", "6", ",", "netID", ")", "\n", "case", "2", ":", "a", ".", "setAddrPrefix", "(", "3", ",", "9", ",", "netID", ")", "\n", "case", "3", ":", "a", ".", "setAddrPrefix", "(", "4", ",", "10", ",", "netID", ")", "\n", "case", "4", ":", "a", ".", "setAddrPrefix", "(", "5", ",", "11", ",", "netID", ")", "\n", "case", "5", ":", "a", ".", "setAddrPrefix", "(", "6", ",", "13", ",", "netID", ")", "\n", "case", "6", ":", "a", ".", "setAddrPrefix", "(", "7", ",", "15", ",", "netID", ")", "\n", "case", "7", ":", "a", ".", "setAddrPrefix", "(", "8", ",", "17", ",", "netID", ")", "\n", "}", "\n", "}" ]
// SetAddrPrefix sets the NetID based AddrPrefix.
[ "SetAddrPrefix", "sets", "the", "NetID", "based", "AddrPrefix", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/fhdr.go#L48-L67
144,274
brocaar/lorawan
fhdr.go
IsNetID
func (a DevAddr) IsNetID(netID NetID) bool { tempDevAddr := a tempDevAddr.SetAddrPrefix(netID) if a == tempDevAddr { return true } return false }
go
func (a DevAddr) IsNetID(netID NetID) bool { tempDevAddr := a tempDevAddr.SetAddrPrefix(netID) if a == tempDevAddr { return true } return false }
[ "func", "(", "a", "DevAddr", ")", "IsNetID", "(", "netID", "NetID", ")", "bool", "{", "tempDevAddr", ":=", "a", "\n", "tempDevAddr", ".", "SetAddrPrefix", "(", "netID", ")", "\n\n", "if", "a", "==", "tempDevAddr", "{", "return", "true", "\n", "}", "\n\n", "return", "false", "\n", "}" ]
// IsNetID returns a bool indicating if the NwkID matches the given NetID.
[ "IsNetID", "returns", "a", "bool", "indicating", "if", "the", "NwkID", "matches", "the", "given", "NetID", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/fhdr.go#L70-L79
144,275
brocaar/lorawan
netid.go
ID
func (n NetID) ID() []byte { switch n.Type() { case 0, 1: return n.getID(6) case 2: return n.getID(9) case 3, 4, 5, 6, 7: return n.getID(21) default: return nil } }
go
func (n NetID) ID() []byte { switch n.Type() { case 0, 1: return n.getID(6) case 2: return n.getID(9) case 3, 4, 5, 6, 7: return n.getID(21) default: return nil } }
[ "func", "(", "n", "NetID", ")", "ID", "(", ")", "[", "]", "byte", "{", "switch", "n", ".", "Type", "(", ")", "{", "case", "0", ",", "1", ":", "return", "n", ".", "getID", "(", "6", ")", "\n", "case", "2", ":", "return", "n", ".", "getID", "(", "9", ")", "\n", "case", "3", ",", "4", ",", "5", ",", "6", ",", "7", ":", "return", "n", ".", "getID", "(", "21", ")", "\n", "default", ":", "return", "nil", "\n", "}", "\n", "}" ]
// ID returns the NetID ID part.
[ "ID", "returns", "the", "NetID", "ID", "part", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/netid.go#L20-L31
144,276
brocaar/lorawan
airtime/airtime.go
CalculateLoRaAirtime
func CalculateLoRaAirtime(payloadSize, sf, bandwidth, preambleNumber int, codingRate CodingRate, headerEnabled, lowDataRateOptimization bool) (time.Duration, error) { symbolDuration := CalculateLoRaSymbolDuration(sf, bandwidth) preambleDuration := CalculateLoRaPreambleDuration(symbolDuration, preambleNumber) payloadSymbolNumber, err := CalculateLoRaPayloadSymbolNumber(payloadSize, sf, codingRate, headerEnabled, lowDataRateOptimization) if err != nil { return 0, err } return preambleDuration + (time.Duration(payloadSymbolNumber) * symbolDuration), nil }
go
func CalculateLoRaAirtime(payloadSize, sf, bandwidth, preambleNumber int, codingRate CodingRate, headerEnabled, lowDataRateOptimization bool) (time.Duration, error) { symbolDuration := CalculateLoRaSymbolDuration(sf, bandwidth) preambleDuration := CalculateLoRaPreambleDuration(symbolDuration, preambleNumber) payloadSymbolNumber, err := CalculateLoRaPayloadSymbolNumber(payloadSize, sf, codingRate, headerEnabled, lowDataRateOptimization) if err != nil { return 0, err } return preambleDuration + (time.Duration(payloadSymbolNumber) * symbolDuration), nil }
[ "func", "CalculateLoRaAirtime", "(", "payloadSize", ",", "sf", ",", "bandwidth", ",", "preambleNumber", "int", ",", "codingRate", "CodingRate", ",", "headerEnabled", ",", "lowDataRateOptimization", "bool", ")", "(", "time", ".", "Duration", ",", "error", ")", "{", "symbolDuration", ":=", "CalculateLoRaSymbolDuration", "(", "sf", ",", "bandwidth", ")", "\n", "preambleDuration", ":=", "CalculateLoRaPreambleDuration", "(", "symbolDuration", ",", "preambleNumber", ")", "\n\n", "payloadSymbolNumber", ",", "err", ":=", "CalculateLoRaPayloadSymbolNumber", "(", "payloadSize", ",", "sf", ",", "codingRate", ",", "headerEnabled", ",", "lowDataRateOptimization", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n\n", "return", "preambleDuration", "+", "(", "time", ".", "Duration", "(", "payloadSymbolNumber", ")", "*", "symbolDuration", ")", ",", "nil", "\n", "}" ]
// CalculateLoRaAirtime calculates the airtime for a LoRa modulated frame.
[ "CalculateLoRaAirtime", "calculates", "the", "airtime", "for", "a", "LoRa", "modulated", "frame", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/airtime/airtime.go#L24-L34
144,277
brocaar/lorawan
airtime/airtime.go
CalculateLoRaSymbolDuration
func CalculateLoRaSymbolDuration(sf int, bandwidth int) time.Duration { return time.Duration((1 << uint(sf)) * 1000000 / bandwidth) }
go
func CalculateLoRaSymbolDuration(sf int, bandwidth int) time.Duration { return time.Duration((1 << uint(sf)) * 1000000 / bandwidth) }
[ "func", "CalculateLoRaSymbolDuration", "(", "sf", "int", ",", "bandwidth", "int", ")", "time", ".", "Duration", "{", "return", "time", ".", "Duration", "(", "(", "1", "<<", "uint", "(", "sf", ")", ")", "*", "1000000", "/", "bandwidth", ")", "\n", "}" ]
// CalculateLoRaSymbolDuration calculates the LoRa symbol duration.
[ "CalculateLoRaSymbolDuration", "calculates", "the", "LoRa", "symbol", "duration", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/airtime/airtime.go#L37-L39
144,278
brocaar/lorawan
airtime/airtime.go
CalculateLoRaPreambleDuration
func CalculateLoRaPreambleDuration(symbolDuration time.Duration, preambleNumber int) time.Duration { return time.Duration((100*preambleNumber)+425) * symbolDuration / 100 }
go
func CalculateLoRaPreambleDuration(symbolDuration time.Duration, preambleNumber int) time.Duration { return time.Duration((100*preambleNumber)+425) * symbolDuration / 100 }
[ "func", "CalculateLoRaPreambleDuration", "(", "symbolDuration", "time", ".", "Duration", ",", "preambleNumber", "int", ")", "time", ".", "Duration", "{", "return", "time", ".", "Duration", "(", "(", "100", "*", "preambleNumber", ")", "+", "425", ")", "*", "symbolDuration", "/", "100", "\n", "}" ]
// CalculateLoRaPreambleDuration calculates the LoRa preamble duration.
[ "CalculateLoRaPreambleDuration", "calculates", "the", "LoRa", "preamble", "duration", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/airtime/airtime.go#L42-L44
144,279
brocaar/lorawan
airtime/airtime.go
CalculateLoRaPayloadSymbolNumber
func CalculateLoRaPayloadSymbolNumber(payloadSize, sf int, codingRate CodingRate, headerEnabled, lowDataRateOptimization bool) (int, error) { var pl, spreadingFactor, h, de, cr float64 if codingRate < 1 || codingRate > 4 { return 0, errors.New("codingRate must be between 1 - 4") } if lowDataRateOptimization { de = 1 } if !headerEnabled { h = 1 } pl = float64(payloadSize) spreadingFactor = float64(sf) cr = float64(codingRate) a := 8*pl - 4*spreadingFactor + 28 + 16 - 20*h b := 4 * (spreadingFactor - 2*de) c := cr + 4 return int(8 + math.Max(math.Ceil(a/b)*c, 0)), nil }
go
func CalculateLoRaPayloadSymbolNumber(payloadSize, sf int, codingRate CodingRate, headerEnabled, lowDataRateOptimization bool) (int, error) { var pl, spreadingFactor, h, de, cr float64 if codingRate < 1 || codingRate > 4 { return 0, errors.New("codingRate must be between 1 - 4") } if lowDataRateOptimization { de = 1 } if !headerEnabled { h = 1 } pl = float64(payloadSize) spreadingFactor = float64(sf) cr = float64(codingRate) a := 8*pl - 4*spreadingFactor + 28 + 16 - 20*h b := 4 * (spreadingFactor - 2*de) c := cr + 4 return int(8 + math.Max(math.Ceil(a/b)*c, 0)), nil }
[ "func", "CalculateLoRaPayloadSymbolNumber", "(", "payloadSize", ",", "sf", "int", ",", "codingRate", "CodingRate", ",", "headerEnabled", ",", "lowDataRateOptimization", "bool", ")", "(", "int", ",", "error", ")", "{", "var", "pl", ",", "spreadingFactor", ",", "h", ",", "de", ",", "cr", "float64", "\n\n", "if", "codingRate", "<", "1", "||", "codingRate", ">", "4", "{", "return", "0", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "if", "lowDataRateOptimization", "{", "de", "=", "1", "\n", "}", "\n\n", "if", "!", "headerEnabled", "{", "h", "=", "1", "\n", "}", "\n\n", "pl", "=", "float64", "(", "payloadSize", ")", "\n", "spreadingFactor", "=", "float64", "(", "sf", ")", "\n", "cr", "=", "float64", "(", "codingRate", ")", "\n\n", "a", ":=", "8", "*", "pl", "-", "4", "*", "spreadingFactor", "+", "28", "+", "16", "-", "20", "*", "h", "\n", "b", ":=", "4", "*", "(", "spreadingFactor", "-", "2", "*", "de", ")", "\n", "c", ":=", "cr", "+", "4", "\n\n", "return", "int", "(", "8", "+", "math", ".", "Max", "(", "math", ".", "Ceil", "(", "a", "/", "b", ")", "*", "c", ",", "0", ")", ")", ",", "nil", "\n", "}" ]
// CalculateLoRaPayloadSymbolNumber returns the number of symbols that make // up the packet payload and header.
[ "CalculateLoRaPayloadSymbolNumber", "returns", "the", "number", "of", "symbols", "that", "make", "up", "the", "packet", "payload", "and", "header", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/airtime/airtime.go#L48-L72
144,280
brocaar/lorawan
applayer/fragmentation/encode.go
Encode
func Encode(data []byte, fragmentSize, redundancy int) ([][]byte, error) { if len(data)%fragmentSize != 0 { return nil, errors.New("length of data must be a multiple of the given fragment-size") } // fragment the data into rows var dataRows [][]byte for i := 0; i < len(data)/fragmentSize; i++ { offset := i * fragmentSize dataRows = append(dataRows, data[offset:offset+fragmentSize]) } w := len(dataRows) for y := 0; y < redundancy; y++ { s := make([]byte, fragmentSize) a := matrixLine(y+1, w) for x := 0; x < w; x++ { if a[x] == 1 { for m := 0; m < fragmentSize; m++ { s[m] ^= dataRows[x][m] } } } dataRows = append(dataRows, s) } return dataRows, nil }
go
func Encode(data []byte, fragmentSize, redundancy int) ([][]byte, error) { if len(data)%fragmentSize != 0 { return nil, errors.New("length of data must be a multiple of the given fragment-size") } // fragment the data into rows var dataRows [][]byte for i := 0; i < len(data)/fragmentSize; i++ { offset := i * fragmentSize dataRows = append(dataRows, data[offset:offset+fragmentSize]) } w := len(dataRows) for y := 0; y < redundancy; y++ { s := make([]byte, fragmentSize) a := matrixLine(y+1, w) for x := 0; x < w; x++ { if a[x] == 1 { for m := 0; m < fragmentSize; m++ { s[m] ^= dataRows[x][m] } } } dataRows = append(dataRows, s) } return dataRows, nil }
[ "func", "Encode", "(", "data", "[", "]", "byte", ",", "fragmentSize", ",", "redundancy", "int", ")", "(", "[", "]", "[", "]", "byte", ",", "error", ")", "{", "if", "len", "(", "data", ")", "%", "fragmentSize", "!=", "0", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "// fragment the data into rows", "var", "dataRows", "[", "]", "[", "]", "byte", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "data", ")", "/", "fragmentSize", ";", "i", "++", "{", "offset", ":=", "i", "*", "fragmentSize", "\n", "dataRows", "=", "append", "(", "dataRows", ",", "data", "[", "offset", ":", "offset", "+", "fragmentSize", "]", ")", "\n", "}", "\n", "w", ":=", "len", "(", "dataRows", ")", "\n\n", "for", "y", ":=", "0", ";", "y", "<", "redundancy", ";", "y", "++", "{", "s", ":=", "make", "(", "[", "]", "byte", ",", "fragmentSize", ")", "\n", "a", ":=", "matrixLine", "(", "y", "+", "1", ",", "w", ")", "\n\n", "for", "x", ":=", "0", ";", "x", "<", "w", ";", "x", "++", "{", "if", "a", "[", "x", "]", "==", "1", "{", "for", "m", ":=", "0", ";", "m", "<", "fragmentSize", ";", "m", "++", "{", "s", "[", "m", "]", "^=", "dataRows", "[", "x", "]", "[", "m", "]", "\n", "}", "\n", "}", "\n", "}", "\n\n", "dataRows", "=", "append", "(", "dataRows", ",", "s", ")", "\n", "}", "\n\n", "return", "dataRows", ",", "nil", "\n", "}" ]
// Encode encodes the given slice of bytes to fragments including forward error correction. // This is based on the proposed FEC code from the Fragmented Data Block Transport over // LoRaWAN recommendation.
[ "Encode", "encodes", "the", "given", "slice", "of", "bytes", "to", "fragments", "including", "forward", "error", "correction", ".", "This", "is", "based", "on", "the", "proposed", "FEC", "code", "from", "the", "Fragmented", "Data", "Block", "Transport", "over", "LoRaWAN", "recommendation", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/applayer/fragmentation/encode.go#L10-L39
144,281
brocaar/lorawan
backend/joinserver/session_keys.go
getJSIntKey
func getJSIntKey(nwkKey lorawan.AES128Key, devEUI lorawan.EUI64) (lorawan.AES128Key, error) { return getJSKey(0x06, devEUI, nwkKey) }
go
func getJSIntKey(nwkKey lorawan.AES128Key, devEUI lorawan.EUI64) (lorawan.AES128Key, error) { return getJSKey(0x06, devEUI, nwkKey) }
[ "func", "getJSIntKey", "(", "nwkKey", "lorawan", ".", "AES128Key", ",", "devEUI", "lorawan", ".", "EUI64", ")", "(", "lorawan", ".", "AES128Key", ",", "error", ")", "{", "return", "getJSKey", "(", "0x06", ",", "devEUI", ",", "nwkKey", ")", "\n", "}" ]
// getJSIntKey returns the JSIntKey.
[ "getJSIntKey", "returns", "the", "JSIntKey", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/backend/joinserver/session_keys.go#L34-L36
144,282
brocaar/lorawan
backend/joinserver/session_keys.go
getJSEncKey
func getJSEncKey(nwkKey lorawan.AES128Key, devEUI lorawan.EUI64) (lorawan.AES128Key, error) { return getJSKey(0x05, devEUI, nwkKey) }
go
func getJSEncKey(nwkKey lorawan.AES128Key, devEUI lorawan.EUI64) (lorawan.AES128Key, error) { return getJSKey(0x05, devEUI, nwkKey) }
[ "func", "getJSEncKey", "(", "nwkKey", "lorawan", ".", "AES128Key", ",", "devEUI", "lorawan", ".", "EUI64", ")", "(", "lorawan", ".", "AES128Key", ",", "error", ")", "{", "return", "getJSKey", "(", "0x05", ",", "devEUI", ",", "nwkKey", ")", "\n", "}" ]
// getJSEncKey returns the JSEncKey.
[ "getJSEncKey", "returns", "the", "JSEncKey", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/backend/joinserver/session_keys.go#L39-L41
144,283
brocaar/lorawan
band/band.go
intSliceDiff
func intSliceDiff(x, y []int) []int { var out []int for _, cX := range x { found := false for _, cY := range y { if cX == cY { found = true break } } if !found { out = append(out, cX) } } for _, cY := range y { found := false for _, cX := range x { if cY == cX { found = true break } } if !found { out = append(out, cY) } } return out }
go
func intSliceDiff(x, y []int) []int { var out []int for _, cX := range x { found := false for _, cY := range y { if cX == cY { found = true break } } if !found { out = append(out, cX) } } for _, cY := range y { found := false for _, cX := range x { if cY == cX { found = true break } } if !found { out = append(out, cY) } } return out }
[ "func", "intSliceDiff", "(", "x", ",", "y", "[", "]", "int", ")", "[", "]", "int", "{", "var", "out", "[", "]", "int", "\n\n", "for", "_", ",", "cX", ":=", "range", "x", "{", "found", ":=", "false", "\n", "for", "_", ",", "cY", ":=", "range", "y", "{", "if", "cX", "==", "cY", "{", "found", "=", "true", "\n", "break", "\n", "}", "\n", "}", "\n", "if", "!", "found", "{", "out", "=", "append", "(", "out", ",", "cX", ")", "\n", "}", "\n", "}", "\n\n", "for", "_", ",", "cY", ":=", "range", "y", "{", "found", ":=", "false", "\n", "for", "_", ",", "cX", ":=", "range", "x", "{", "if", "cY", "==", "cX", "{", "found", "=", "true", "\n", "break", "\n", "}", "\n", "}", "\n", "if", "!", "found", "{", "out", "=", "append", "(", "out", ",", "cY", ")", "\n", "}", "\n", "}", "\n\n", "return", "out", "\n", "}" ]
// y that are not in x.
[ "y", "that", "are", "not", "in", "x", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/band/band.go#L558-L588
144,284
brocaar/lorawan
band/band.go
GetConfig
func GetConfig(name Name, repeaterCompatible bool, dt lorawan.DwellTime) (Band, error) { switch name { case AS_923, AS923: return newAS923Band(repeaterCompatible, dt) case AU_915_928, AU915: return newAU915Band(repeaterCompatible, dt) case CN_470_510, CN470: return newCN470Band(repeaterCompatible) case CN_779_787, CN779: return newCN779Band(repeaterCompatible) case EU_433, EU433: return newEU433Band(repeaterCompatible) case EU_863_870, EU868: return newEU863Band(repeaterCompatible) case IN_865_867, IN865: return newIN865Band(repeaterCompatible) case KR_920_923, KR920: return newKR920Band(repeaterCompatible) case US_902_928, US915: return newUS902Band(repeaterCompatible) case RU_864_870, RU864: return newRU864Band(repeaterCompatible) default: return nil, fmt.Errorf("lorawan/band: band %s is undefined", name) } }
go
func GetConfig(name Name, repeaterCompatible bool, dt lorawan.DwellTime) (Band, error) { switch name { case AS_923, AS923: return newAS923Band(repeaterCompatible, dt) case AU_915_928, AU915: return newAU915Band(repeaterCompatible, dt) case CN_470_510, CN470: return newCN470Band(repeaterCompatible) case CN_779_787, CN779: return newCN779Band(repeaterCompatible) case EU_433, EU433: return newEU433Band(repeaterCompatible) case EU_863_870, EU868: return newEU863Band(repeaterCompatible) case IN_865_867, IN865: return newIN865Band(repeaterCompatible) case KR_920_923, KR920: return newKR920Band(repeaterCompatible) case US_902_928, US915: return newUS902Band(repeaterCompatible) case RU_864_870, RU864: return newRU864Band(repeaterCompatible) default: return nil, fmt.Errorf("lorawan/band: band %s is undefined", name) } }
[ "func", "GetConfig", "(", "name", "Name", ",", "repeaterCompatible", "bool", ",", "dt", "lorawan", ".", "DwellTime", ")", "(", "Band", ",", "error", ")", "{", "switch", "name", "{", "case", "AS_923", ",", "AS923", ":", "return", "newAS923Band", "(", "repeaterCompatible", ",", "dt", ")", "\n", "case", "AU_915_928", ",", "AU915", ":", "return", "newAU915Band", "(", "repeaterCompatible", ",", "dt", ")", "\n", "case", "CN_470_510", ",", "CN470", ":", "return", "newCN470Band", "(", "repeaterCompatible", ")", "\n", "case", "CN_779_787", ",", "CN779", ":", "return", "newCN779Band", "(", "repeaterCompatible", ")", "\n", "case", "EU_433", ",", "EU433", ":", "return", "newEU433Band", "(", "repeaterCompatible", ")", "\n", "case", "EU_863_870", ",", "EU868", ":", "return", "newEU863Band", "(", "repeaterCompatible", ")", "\n", "case", "IN_865_867", ",", "IN865", ":", "return", "newIN865Band", "(", "repeaterCompatible", ")", "\n", "case", "KR_920_923", ",", "KR920", ":", "return", "newKR920Band", "(", "repeaterCompatible", ")", "\n", "case", "US_902_928", ",", "US915", ":", "return", "newUS902Band", "(", "repeaterCompatible", ")", "\n", "case", "RU_864_870", ",", "RU864", ":", "return", "newRU864Band", "(", "repeaterCompatible", ")", "\n", "default", ":", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "name", ")", "\n", "}", "\n", "}" ]
// GetConfig returns the band configuration for the given band. // Please refer to the LoRaWAN specification for more details about the effect // of the repeater and dwell time arguments.
[ "GetConfig", "returns", "the", "band", "configuration", "for", "the", "given", "band", ".", "Please", "refer", "to", "the", "LoRaWAN", "specification", "for", "more", "details", "about", "the", "effect", "of", "the", "repeater", "and", "dwell", "time", "arguments", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/band/band.go#L602-L627
144,285
brocaar/lorawan
mac_commands.go
GetMACPayloadAndSize
func GetMACPayloadAndSize(uplink bool, c CID) (MACCommandPayload, int, error) { macPayloadMutex.RLock() defer macPayloadMutex.RUnlock() v, ok := macPayloadRegistry[uplink][c] if !ok { return nil, 0, fmt.Errorf("lorawan: payload unknown for uplink=%v and CID=%v", uplink, c) } return v.payload(), v.size, nil }
go
func GetMACPayloadAndSize(uplink bool, c CID) (MACCommandPayload, int, error) { macPayloadMutex.RLock() defer macPayloadMutex.RUnlock() v, ok := macPayloadRegistry[uplink][c] if !ok { return nil, 0, fmt.Errorf("lorawan: payload unknown for uplink=%v and CID=%v", uplink, c) } return v.payload(), v.size, nil }
[ "func", "GetMACPayloadAndSize", "(", "uplink", "bool", ",", "c", "CID", ")", "(", "MACCommandPayload", ",", "int", ",", "error", ")", "{", "macPayloadMutex", ".", "RLock", "(", ")", "\n", "defer", "macPayloadMutex", ".", "RUnlock", "(", ")", "\n\n", "v", ",", "ok", ":=", "macPayloadRegistry", "[", "uplink", "]", "[", "c", "]", "\n", "if", "!", "ok", "{", "return", "nil", ",", "0", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "uplink", ",", "c", ")", "\n", "}", "\n\n", "return", "v", ".", "payload", "(", ")", ",", "v", ".", "size", ",", "nil", "\n", "}" ]
// GetMACPayloadAndSize returns a new MACCommandPayload instance and it's size.
[ "GetMACPayloadAndSize", "returns", "a", "new", "MACCommandPayload", "instance", "and", "it", "s", "size", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/mac_commands.go#L134-L144
144,286
brocaar/lorawan
mac_commands.go
RegisterProprietaryMACCommand
func RegisterProprietaryMACCommand(uplink bool, cid CID, payloadSize int) error { if !(cid >= 128 && cid <= 255) { return fmt.Errorf("lorawan: invalid CID %x", byte(cid)) } if payloadSize == 0 { // no need to register the payload size return nil } macPayloadMutex.Lock() defer macPayloadMutex.Unlock() macPayloadRegistry[uplink][cid] = macPayloadInfo{ size: payloadSize, payload: func() MACCommandPayload { return &ProprietaryMACCommandPayload{} }, } return nil }
go
func RegisterProprietaryMACCommand(uplink bool, cid CID, payloadSize int) error { if !(cid >= 128 && cid <= 255) { return fmt.Errorf("lorawan: invalid CID %x", byte(cid)) } if payloadSize == 0 { // no need to register the payload size return nil } macPayloadMutex.Lock() defer macPayloadMutex.Unlock() macPayloadRegistry[uplink][cid] = macPayloadInfo{ size: payloadSize, payload: func() MACCommandPayload { return &ProprietaryMACCommandPayload{} }, } return nil }
[ "func", "RegisterProprietaryMACCommand", "(", "uplink", "bool", ",", "cid", "CID", ",", "payloadSize", "int", ")", "error", "{", "if", "!", "(", "cid", ">=", "128", "&&", "cid", "<=", "255", ")", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "byte", "(", "cid", ")", ")", "\n", "}", "\n\n", "if", "payloadSize", "==", "0", "{", "// no need to register the payload size", "return", "nil", "\n", "}", "\n\n", "macPayloadMutex", ".", "Lock", "(", ")", "\n", "defer", "macPayloadMutex", ".", "Unlock", "(", ")", "\n\n", "macPayloadRegistry", "[", "uplink", "]", "[", "cid", "]", "=", "macPayloadInfo", "{", "size", ":", "payloadSize", ",", "payload", ":", "func", "(", ")", "MACCommandPayload", "{", "return", "&", "ProprietaryMACCommandPayload", "{", "}", "}", ",", "}", "\n\n", "return", "nil", "\n", "}" ]
// RegisterProprietaryMACCommand registers a proprietary MAC command. Note // that there is no need to call this when the size of the payload is > 0 bytes.
[ "RegisterProprietaryMACCommand", "registers", "a", "proprietary", "MAC", "command", ".", "Note", "that", "there", "is", "no", "need", "to", "call", "this", "when", "the", "size", "of", "the", "payload", "is", ">", "0", "bytes", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/mac_commands.go#L148-L167
144,287
brocaar/lorawan
mac_commands.go
UnmarshalBinary
func (p *ProprietaryMACCommandPayload) UnmarshalBinary(data []byte) error { p.Bytes = data return nil }
go
func (p *ProprietaryMACCommandPayload) UnmarshalBinary(data []byte) error { p.Bytes = data return nil }
[ "func", "(", "p", "*", "ProprietaryMACCommandPayload", ")", "UnmarshalBinary", "(", "data", "[", "]", "byte", ")", "error", "{", "p", ".", "Bytes", "=", "data", "\n", "return", "nil", "\n", "}" ]
// UnmarshalBinary decodes the object from a slice of bytes.
[ "UnmarshalBinary", "decodes", "the", "object", "from", "a", "slice", "of", "bytes", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/mac_commands.go#L228-L231
144,288
brocaar/lorawan
mac_commands.go
MarshalBinary
func (p TXParamSetupReqPayload) MarshalBinary() ([]byte, error) { var b uint8 for i, v := range []uint8{8, 10, 12, 13, 14, 16, 18, 20, 21, 24, 26, 27, 29, 30, 33, 36} { if v == p.MaxEIRP { b = uint8(i) } } if b == 0 { return nil, errors.New("lorawan: invalid MaxEIRP value") } if p.UplinkDwellTime == DwellTime400ms { b = b ^ (1 << 4) } if p.DownlinkDwelltime == DwellTime400ms { b = b ^ (1 << 5) } return []byte{b}, nil }
go
func (p TXParamSetupReqPayload) MarshalBinary() ([]byte, error) { var b uint8 for i, v := range []uint8{8, 10, 12, 13, 14, 16, 18, 20, 21, 24, 26, 27, 29, 30, 33, 36} { if v == p.MaxEIRP { b = uint8(i) } } if b == 0 { return nil, errors.New("lorawan: invalid MaxEIRP value") } if p.UplinkDwellTime == DwellTime400ms { b = b ^ (1 << 4) } if p.DownlinkDwelltime == DwellTime400ms { b = b ^ (1 << 5) } return []byte{b}, nil }
[ "func", "(", "p", "TXParamSetupReqPayload", ")", "MarshalBinary", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "var", "b", "uint8", "\n", "for", "i", ",", "v", ":=", "range", "[", "]", "uint8", "{", "8", ",", "10", ",", "12", ",", "13", ",", "14", ",", "16", ",", "18", ",", "20", ",", "21", ",", "24", ",", "26", ",", "27", ",", "29", ",", "30", ",", "33", ",", "36", "}", "{", "if", "v", "==", "p", ".", "MaxEIRP", "{", "b", "=", "uint8", "(", "i", ")", "\n", "}", "\n", "}", "\n", "if", "b", "==", "0", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "if", "p", ".", "UplinkDwellTime", "==", "DwellTime400ms", "{", "b", "=", "b", "^", "(", "1", "<<", "4", ")", "\n", "}", "\n", "if", "p", ".", "DownlinkDwelltime", "==", "DwellTime400ms", "{", "b", "=", "b", "^", "(", "1", "<<", "5", ")", "\n", "}", "\n\n", "return", "[", "]", "byte", "{", "b", "}", ",", "nil", "\n", "}" ]
// MarshalBinary encodes the object into a bytes.
[ "MarshalBinary", "encodes", "the", "object", "into", "a", "bytes", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/mac_commands.go#L706-L725
144,289
brocaar/lorawan
mac_commands.go
decodeDataPayloadToMACCommands
func decodeDataPayloadToMACCommands(uplink bool, payloads []Payload) ([]Payload, error) { if len(payloads) != 1 { return nil, errors.New("lorawan: exactly one Payload expected") } dataPL, ok := payloads[0].(*DataPayload) if !ok { return nil, fmt.Errorf("lorawan: expected *DataPayload, got %T", payloads[0]) } var plLen int var out []Payload for i := 0; i < len(dataPL.Bytes); i++ { if _, s, err := GetMACPayloadAndSize(uplink, CID(dataPL.Bytes[i])); err != nil { plLen = 0 } else { plLen = s } if len(dataPL.Bytes[i:]) < plLen+1 { return nil, errors.New("lorawan: not enough remaining bytes") } mc := &MACCommand{} if err := mc.UnmarshalBinary(uplink, dataPL.Bytes[i:i+1+plLen]); err != nil { log.Printf("warning: unmarshal mac-command error (skipping remaining mac-command bytes): %s", err) } out = append(out, mc) i = i + plLen } return out, nil }
go
func decodeDataPayloadToMACCommands(uplink bool, payloads []Payload) ([]Payload, error) { if len(payloads) != 1 { return nil, errors.New("lorawan: exactly one Payload expected") } dataPL, ok := payloads[0].(*DataPayload) if !ok { return nil, fmt.Errorf("lorawan: expected *DataPayload, got %T", payloads[0]) } var plLen int var out []Payload for i := 0; i < len(dataPL.Bytes); i++ { if _, s, err := GetMACPayloadAndSize(uplink, CID(dataPL.Bytes[i])); err != nil { plLen = 0 } else { plLen = s } if len(dataPL.Bytes[i:]) < plLen+1 { return nil, errors.New("lorawan: not enough remaining bytes") } mc := &MACCommand{} if err := mc.UnmarshalBinary(uplink, dataPL.Bytes[i:i+1+plLen]); err != nil { log.Printf("warning: unmarshal mac-command error (skipping remaining mac-command bytes): %s", err) } out = append(out, mc) i = i + plLen } return out, nil }
[ "func", "decodeDataPayloadToMACCommands", "(", "uplink", "bool", ",", "payloads", "[", "]", "Payload", ")", "(", "[", "]", "Payload", ",", "error", ")", "{", "if", "len", "(", "payloads", ")", "!=", "1", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "dataPL", ",", "ok", ":=", "payloads", "[", "0", "]", ".", "(", "*", "DataPayload", ")", "\n", "if", "!", "ok", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "payloads", "[", "0", "]", ")", "\n", "}", "\n\n", "var", "plLen", "int", "\n", "var", "out", "[", "]", "Payload", "\n\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "dataPL", ".", "Bytes", ")", ";", "i", "++", "{", "if", "_", ",", "s", ",", "err", ":=", "GetMACPayloadAndSize", "(", "uplink", ",", "CID", "(", "dataPL", ".", "Bytes", "[", "i", "]", ")", ")", ";", "err", "!=", "nil", "{", "plLen", "=", "0", "\n", "}", "else", "{", "plLen", "=", "s", "\n", "}", "\n\n", "if", "len", "(", "dataPL", ".", "Bytes", "[", "i", ":", "]", ")", "<", "plLen", "+", "1", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "mc", ":=", "&", "MACCommand", "{", "}", "\n", "if", "err", ":=", "mc", ".", "UnmarshalBinary", "(", "uplink", ",", "dataPL", ".", "Bytes", "[", "i", ":", "i", "+", "1", "+", "plLen", "]", ")", ";", "err", "!=", "nil", "{", "log", ".", "Printf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "out", "=", "append", "(", "out", ",", "mc", ")", "\n", "i", "=", "i", "+", "plLen", "\n", "}", "\n\n", "return", "out", ",", "nil", "\n", "}" ]
// decodeDataPayloadToMACCommands decodes a DataPayload into a slice of // MACCommands.
[ "decodeDataPayloadToMACCommands", "decodes", "a", "DataPayload", "into", "a", "slice", "of", "MACCommands", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/mac_commands.go#L1278-L1312
144,290
brocaar/lorawan
applayer/clocksync/clocksync.go
UnmarshalBinary
func (p *AppTimeAnsPayload) UnmarshalBinary(data []byte) error { if len(data) < p.Size() { return fmt.Errorf("lorawan/applayer/clocksync: %d bytes are expected", p.Size()) } p.TimeCorrection = int32(binary.LittleEndian.Uint32(data[0:4])) p.Param.TokenAns = uint8(data[4] & 0x0f) return nil }
go
func (p *AppTimeAnsPayload) UnmarshalBinary(data []byte) error { if len(data) < p.Size() { return fmt.Errorf("lorawan/applayer/clocksync: %d bytes are expected", p.Size()) } p.TimeCorrection = int32(binary.LittleEndian.Uint32(data[0:4])) p.Param.TokenAns = uint8(data[4] & 0x0f) return nil }
[ "func", "(", "p", "*", "AppTimeAnsPayload", ")", "UnmarshalBinary", "(", "data", "[", "]", "byte", ")", "error", "{", "if", "len", "(", "data", ")", "<", "p", ".", "Size", "(", ")", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "p", ".", "Size", "(", ")", ")", "\n", "}", "\n\n", "p", ".", "TimeCorrection", "=", "int32", "(", "binary", ".", "LittleEndian", ".", "Uint32", "(", "data", "[", "0", ":", "4", "]", ")", ")", "\n", "p", ".", "Param", ".", "TokenAns", "=", "uint8", "(", "data", "[", "4", "]", "&", "0x0f", ")", "\n\n", "return", "nil", "\n", "}" ]
// UnmarshalBinary decoces the payload from a slice of bytes.
[ "UnmarshalBinary", "decoces", "the", "payload", "from", "a", "slice", "of", "bytes", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/applayer/clocksync/clocksync.go#L253-L262
144,291
brocaar/lorawan
applayer/fragmentation/fragmentation.go
MarshalBinary
func (p DataFragmentPayload) MarshalBinary() ([]byte, error) { b := make([]byte, p.Size()) binary.LittleEndian.PutUint16(b[0:2], p.IndexAndN.N&0x3fff) b[1] |= (p.IndexAndN.FragIndex & 0x03) << 6 copy(b[2:], p.Payload) return b, nil }
go
func (p DataFragmentPayload) MarshalBinary() ([]byte, error) { b := make([]byte, p.Size()) binary.LittleEndian.PutUint16(b[0:2], p.IndexAndN.N&0x3fff) b[1] |= (p.IndexAndN.FragIndex & 0x03) << 6 copy(b[2:], p.Payload) return b, nil }
[ "func", "(", "p", "DataFragmentPayload", ")", "MarshalBinary", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "b", ":=", "make", "(", "[", "]", "byte", ",", "p", ".", "Size", "(", ")", ")", "\n\n", "binary", ".", "LittleEndian", ".", "PutUint16", "(", "b", "[", "0", ":", "2", "]", ",", "p", ".", "IndexAndN", ".", "N", "&", "0x3fff", ")", "\n", "b", "[", "1", "]", "|=", "(", "p", ".", "IndexAndN", ".", "FragIndex", "&", "0x03", ")", "<<", "6", "\n", "copy", "(", "b", "[", "2", ":", "]", ",", "p", ".", "Payload", ")", "\n\n", "return", "b", ",", "nil", "\n", "}" ]
// MarshalBinary encodes the given payload to a slice of bytes.
[ "MarshalBinary", "encodes", "the", "given", "payload", "to", "a", "slice", "of", "bytes", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/applayer/fragmentation/fragmentation.go#L419-L427
144,292
Netflix/rend
server/listen.go
TCPListener
func TCPListener(port int) ListenConst { return func() (Listener, error) { listener, err := net.Listen("tcp", fmt.Sprintf(":%d", port)) if err != nil { return nil, fmt.Errorf("Error binding to port %d: %v", port, err.Error()) } return &tcpListener{listener: listener}, nil } }
go
func TCPListener(port int) ListenConst { return func() (Listener, error) { listener, err := net.Listen("tcp", fmt.Sprintf(":%d", port)) if err != nil { return nil, fmt.Errorf("Error binding to port %d: %v", port, err.Error()) } return &tcpListener{listener: listener}, nil } }
[ "func", "TCPListener", "(", "port", "int", ")", "ListenConst", "{", "return", "func", "(", ")", "(", "Listener", ",", "error", ")", "{", "listener", ",", "err", ":=", "net", ".", "Listen", "(", "\"", "\"", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "port", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "port", ",", "err", ".", "Error", "(", ")", ")", "\n", "}", "\n", "return", "&", "tcpListener", "{", "listener", ":", "listener", "}", ",", "nil", "\n", "}", "\n", "}" ]
// TCPListener is a ListenConst that returns a tcp listener for the given port
[ "TCPListener", "is", "a", "ListenConst", "that", "returns", "a", "tcp", "listener", "for", "the", "given", "port" ]
d3db570668d3ecd97cbdf0988c92145a9040e235
https://github.com/Netflix/rend/blob/d3db570668d3ecd97cbdf0988c92145a9040e235/server/listen.go#L55-L63
144,293
Netflix/rend
server/listen.go
UnixListener
func UnixListener(path string) ListenConst { return func() (Listener, error) { err := os.Remove(path) if err != nil && !os.IsNotExist(err) { return nil, fmt.Errorf("Error removing previous unix socket file at %s", path) } listener, err := net.Listen("unix", path) if err != nil { return nil, fmt.Errorf("Error binding to unix socket at %s: %v", path, err.Error()) } return &unixListener{listener: listener}, nil } }
go
func UnixListener(path string) ListenConst { return func() (Listener, error) { err := os.Remove(path) if err != nil && !os.IsNotExist(err) { return nil, fmt.Errorf("Error removing previous unix socket file at %s", path) } listener, err := net.Listen("unix", path) if err != nil { return nil, fmt.Errorf("Error binding to unix socket at %s: %v", path, err.Error()) } return &unixListener{listener: listener}, nil } }
[ "func", "UnixListener", "(", "path", "string", ")", "ListenConst", "{", "return", "func", "(", ")", "(", "Listener", ",", "error", ")", "{", "err", ":=", "os", ".", "Remove", "(", "path", ")", "\n", "if", "err", "!=", "nil", "&&", "!", "os", ".", "IsNotExist", "(", "err", ")", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "path", ")", "\n", "}", "\n\n", "listener", ",", "err", ":=", "net", ".", "Listen", "(", "\"", "\"", ",", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "path", ",", "err", ".", "Error", "(", ")", ")", "\n", "}", "\n\n", "return", "&", "unixListener", "{", "listener", ":", "listener", "}", ",", "nil", "\n", "}", "\n", "}" ]
// UnixListener is a ListenConst that returns a unix domain socket listener for the given path
[ "UnixListener", "is", "a", "ListenConst", "that", "returns", "a", "unix", "domain", "socket", "listener", "for", "the", "given", "path" ]
d3db570668d3ecd97cbdf0988c92145a9040e235
https://github.com/Netflix/rend/blob/d3db570668d3ecd97cbdf0988c92145a9040e235/server/listen.go#L78-L92
144,294
Netflix/rend
metrics/bulkcallback.go
RegisterBulkCallback
func RegisterBulkCallback(bcb BulkCallback) { id := atomic.AddUint32(curBulkCbID, 1) - 1 if id >= maxNumCallbacks { panic("Too many callbacks") } bulkCBs[id] = bcb }
go
func RegisterBulkCallback(bcb BulkCallback) { id := atomic.AddUint32(curBulkCbID, 1) - 1 if id >= maxNumCallbacks { panic("Too many callbacks") } bulkCBs[id] = bcb }
[ "func", "RegisterBulkCallback", "(", "bcb", "BulkCallback", ")", "{", "id", ":=", "atomic", ".", "AddUint32", "(", "curBulkCbID", ",", "1", ")", "-", "1", "\n\n", "if", "id", ">=", "maxNumCallbacks", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n\n", "bulkCBs", "[", "id", "]", "=", "bcb", "\n", "}" ]
// RegisterBulkCallback registers a bulk callback which will be called every time // metrics are requested. // There is a maximum of 1024 bulk callbacks, after which adding a new one will panic.
[ "RegisterBulkCallback", "registers", "a", "bulk", "callback", "which", "will", "be", "called", "every", "time", "metrics", "are", "requested", ".", "There", "is", "a", "maximum", "of", "1024", "bulk", "callbacks", "after", "which", "adding", "a", "new", "one", "will", "panic", "." ]
d3db570668d3ecd97cbdf0988c92145a9040e235
https://github.com/Netflix/rend/blob/d3db570668d3ecd97cbdf0988c92145a9040e235/metrics/bulkcallback.go#L38-L46
144,295
Netflix/rend
metrics/gauges.go
AddIntGauge
func AddIntGauge(name string, tgs Tags) uint32 { id := atomic.AddUint32(curIntGaugeID, 1) - 1 if id >= maxNumGauges { panic("Too many int gauges") } intgnames[id] = name tgs = copyTags(tgs) tgs[TagMetricType] = MetricTypeGauge tgs[TagDataType] = DataTypeUint64 intgtags[id] = tgs return id }
go
func AddIntGauge(name string, tgs Tags) uint32 { id := atomic.AddUint32(curIntGaugeID, 1) - 1 if id >= maxNumGauges { panic("Too many int gauges") } intgnames[id] = name tgs = copyTags(tgs) tgs[TagMetricType] = MetricTypeGauge tgs[TagDataType] = DataTypeUint64 intgtags[id] = tgs return id }
[ "func", "AddIntGauge", "(", "name", "string", ",", "tgs", "Tags", ")", "uint32", "{", "id", ":=", "atomic", ".", "AddUint32", "(", "curIntGaugeID", ",", "1", ")", "-", "1", "\n\n", "if", "id", ">=", "maxNumGauges", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n\n", "intgnames", "[", "id", "]", "=", "name", "\n\n", "tgs", "=", "copyTags", "(", "tgs", ")", "\n", "tgs", "[", "TagMetricType", "]", "=", "MetricTypeGauge", "\n", "tgs", "[", "TagDataType", "]", "=", "DataTypeUint64", "\n", "intgtags", "[", "id", "]", "=", "tgs", "\n\n", "return", "id", "\n", "}" ]
// AddIntGauge registers an integer-based gauge and returns an ID that can be // used to update it. // There is a maximum of 1024 gauges, after which adding a new one will panic
[ "AddIntGauge", "registers", "an", "integer", "-", "based", "gauge", "and", "returns", "an", "ID", "that", "can", "be", "used", "to", "update", "it", ".", "There", "is", "a", "maximum", "of", "1024", "gauges", "after", "which", "adding", "a", "new", "one", "will", "panic" ]
d3db570668d3ecd97cbdf0988c92145a9040e235
https://github.com/Netflix/rend/blob/d3db570668d3ecd97cbdf0988c92145a9040e235/metrics/gauges.go#L39-L54
144,296
Netflix/rend
metrics/gauges.go
AddFloatGauge
func AddFloatGauge(name string, tgs Tags) uint32 { id := atomic.AddUint32(curFloatGaugeID, 1) - 1 if id >= maxNumGauges { panic("Too many float gauges") } floatgnames[id] = name tgs = copyTags(tgs) tgs[TagMetricType] = MetricTypeGauge tgs[TagDataType] = DataTypeFloat64 floatgtags[id] = tgs return id }
go
func AddFloatGauge(name string, tgs Tags) uint32 { id := atomic.AddUint32(curFloatGaugeID, 1) - 1 if id >= maxNumGauges { panic("Too many float gauges") } floatgnames[id] = name tgs = copyTags(tgs) tgs[TagMetricType] = MetricTypeGauge tgs[TagDataType] = DataTypeFloat64 floatgtags[id] = tgs return id }
[ "func", "AddFloatGauge", "(", "name", "string", ",", "tgs", "Tags", ")", "uint32", "{", "id", ":=", "atomic", ".", "AddUint32", "(", "curFloatGaugeID", ",", "1", ")", "-", "1", "\n\n", "if", "id", ">=", "maxNumGauges", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n\n", "floatgnames", "[", "id", "]", "=", "name", "\n\n", "tgs", "=", "copyTags", "(", "tgs", ")", "\n", "tgs", "[", "TagMetricType", "]", "=", "MetricTypeGauge", "\n", "tgs", "[", "TagDataType", "]", "=", "DataTypeFloat64", "\n", "floatgtags", "[", "id", "]", "=", "tgs", "\n\n", "return", "id", "\n", "}" ]
// AddFloatGauge registers a float-based gauge and returns an ID that can be // used to access it. // There is a maximum of 1024 gauges, after which adding a new one will panic
[ "AddFloatGauge", "registers", "a", "float", "-", "based", "gauge", "and", "returns", "an", "ID", "that", "can", "be", "used", "to", "access", "it", ".", "There", "is", "a", "maximum", "of", "1024", "gauges", "after", "which", "adding", "a", "new", "one", "will", "panic" ]
d3db570668d3ecd97cbdf0988c92145a9040e235
https://github.com/Netflix/rend/blob/d3db570668d3ecd97cbdf0988c92145a9040e235/metrics/gauges.go#L59-L74
144,297
Netflix/rend
metrics/gauges.go
SetIntGauge
func SetIntGauge(id uint32, value uint64) { atomic.StoreUint64(&intgauges[id], value) }
go
func SetIntGauge(id uint32, value uint64) { atomic.StoreUint64(&intgauges[id], value) }
[ "func", "SetIntGauge", "(", "id", "uint32", ",", "value", "uint64", ")", "{", "atomic", ".", "StoreUint64", "(", "&", "intgauges", "[", "id", "]", ",", "value", ")", "\n", "}" ]
// SetIntGauge sets a gauge by the ID returned from AddIntGauge to the value given.
[ "SetIntGauge", "sets", "a", "gauge", "by", "the", "ID", "returned", "from", "AddIntGauge", "to", "the", "value", "given", "." ]
d3db570668d3ecd97cbdf0988c92145a9040e235
https://github.com/Netflix/rend/blob/d3db570668d3ecd97cbdf0988c92145a9040e235/metrics/gauges.go#L77-L79
144,298
Netflix/rend
metrics/gauges.go
SetFloatGauge
func SetFloatGauge(id uint32, value float64) { // The float64 value needs to be converted into an int64 here because // there is no atomic store for float values. This is a literal // reinterpretation of the same exact bits. v2 := math.Float64bits(value) atomic.StoreUint64(&floatgauges[id], v2) }
go
func SetFloatGauge(id uint32, value float64) { // The float64 value needs to be converted into an int64 here because // there is no atomic store for float values. This is a literal // reinterpretation of the same exact bits. v2 := math.Float64bits(value) atomic.StoreUint64(&floatgauges[id], v2) }
[ "func", "SetFloatGauge", "(", "id", "uint32", ",", "value", "float64", ")", "{", "// The float64 value needs to be converted into an int64 here because", "// there is no atomic store for float values. This is a literal", "// reinterpretation of the same exact bits.", "v2", ":=", "math", ".", "Float64bits", "(", "value", ")", "\n", "atomic", ".", "StoreUint64", "(", "&", "floatgauges", "[", "id", "]", ",", "v2", ")", "\n", "}" ]
// SetFloatGauge sets a gauge by the ID returned from AddFloatGauge to the value given.
[ "SetFloatGauge", "sets", "a", "gauge", "by", "the", "ID", "returned", "from", "AddFloatGauge", "to", "the", "value", "given", "." ]
d3db570668d3ecd97cbdf0988c92145a9040e235
https://github.com/Netflix/rend/blob/d3db570668d3ecd97cbdf0988c92145a9040e235/metrics/gauges.go#L82-L88
144,299
Netflix/rend
client/cmd/setget/main.go
fillKeys
func fillKeys(chans []chan []byte) { totalCap := 0 for _, c := range chans { totalCap += cap(c) } if totalCap < f.NumOps { panic("Channels cannot hold all the ops. Deadlock guaranteed.") } ci := 0 key := bytes.Repeat([]byte{byte('A')}, f.KeyLength) for i := 0; i < f.NumOps; i++ { key = nextKey(key) chans[ci] <- key ci = (ci + 1) % len(chans) } // close them as they have all the data they need for _, c := range chans { close(c) } }
go
func fillKeys(chans []chan []byte) { totalCap := 0 for _, c := range chans { totalCap += cap(c) } if totalCap < f.NumOps { panic("Channels cannot hold all the ops. Deadlock guaranteed.") } ci := 0 key := bytes.Repeat([]byte{byte('A')}, f.KeyLength) for i := 0; i < f.NumOps; i++ { key = nextKey(key) chans[ci] <- key ci = (ci + 1) % len(chans) } // close them as they have all the data they need for _, c := range chans { close(c) } }
[ "func", "fillKeys", "(", "chans", "[", "]", "chan", "[", "]", "byte", ")", "{", "totalCap", ":=", "0", "\n", "for", "_", ",", "c", ":=", "range", "chans", "{", "totalCap", "+=", "cap", "(", "c", ")", "\n", "}", "\n", "if", "totalCap", "<", "f", ".", "NumOps", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n\n", "ci", ":=", "0", "\n", "key", ":=", "bytes", ".", "Repeat", "(", "[", "]", "byte", "{", "byte", "(", "'A'", ")", "}", ",", "f", ".", "KeyLength", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "f", ".", "NumOps", ";", "i", "++", "{", "key", "=", "nextKey", "(", "key", ")", "\n", "chans", "[", "ci", "]", "<-", "key", "\n", "ci", "=", "(", "ci", "+", "1", ")", "%", "len", "(", "chans", ")", "\n", "}", "\n\n", "// close them as they have all the data they need", "for", "_", ",", "c", ":=", "range", "chans", "{", "close", "(", "c", ")", "\n", "}", "\n", "}" ]
// fills a bunch of channels round robin with keys
[ "fills", "a", "bunch", "of", "channels", "round", "robin", "with", "keys" ]
d3db570668d3ecd97cbdf0988c92145a9040e235
https://github.com/Netflix/rend/blob/d3db570668d3ecd97cbdf0988c92145a9040e235/client/cmd/setget/main.go#L80-L101