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 list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 |
|---|---|---|---|---|---|---|---|---|---|---|---|
15,900 | choria-io/go-choria | choria/message.go | NewMessageFromRequest | func NewMessageFromRequest(req protocol.Request, replyto string, choria *Framework) (msg *Message, err error) {
reqm, err := NewMessage(req.Message(), req.Agent(), req.Collective(), "request", nil, choria)
if err != nil {
return msg, fmt.Errorf("could not create request message: %s", err)
}
if replyto != "" {
reqm.replyTo = replyto
}
msg, err = NewMessage(req.Message(), req.Agent(), req.Collective(), "reply", reqm, choria)
if err != nil {
return msg, err
}
msg.RequestID = req.RequestID()
msg.TTL = req.TTL()
msg.TimeStamp = req.Time()
msg.Filter, _ = req.Filter()
msg.SenderID = choria.Config.Identity
msg.SetBase64Payload(req.Message())
msg.req = req
return
} | go | func NewMessageFromRequest(req protocol.Request, replyto string, choria *Framework) (msg *Message, err error) {
reqm, err := NewMessage(req.Message(), req.Agent(), req.Collective(), "request", nil, choria)
if err != nil {
return msg, fmt.Errorf("could not create request message: %s", err)
}
if replyto != "" {
reqm.replyTo = replyto
}
msg, err = NewMessage(req.Message(), req.Agent(), req.Collective(), "reply", reqm, choria)
if err != nil {
return msg, err
}
msg.RequestID = req.RequestID()
msg.TTL = req.TTL()
msg.TimeStamp = req.Time()
msg.Filter, _ = req.Filter()
msg.SenderID = choria.Config.Identity
msg.SetBase64Payload(req.Message())
msg.req = req
return
} | [
"func",
"NewMessageFromRequest",
"(",
"req",
"protocol",
".",
"Request",
",",
"replyto",
"string",
",",
"choria",
"*",
"Framework",
")",
"(",
"msg",
"*",
"Message",
",",
"err",
"error",
")",
"{",
"reqm",
",",
"err",
":=",
"NewMessage",
"(",
"req",
".",
... | // NewMessageFromRequest constructs a Message based on a Request | [
"NewMessageFromRequest",
"constructs",
"a",
"Message",
"based",
"on",
"a",
"Request"
] | 2c773ed36498f426852fd294ebb832c6a2625eba | https://github.com/choria-io/go-choria/blob/2c773ed36498f426852fd294ebb832c6a2625eba/choria/message.go#L40-L64 |
15,901 | choria-io/go-choria | choria/message.go | NewMessage | func NewMessage(payload string, agent string, collective string, msgType string, request *Message, choria *Framework) (msg *Message, err error) {
id, err := choria.NewRequestID()
if err != nil {
return
}
msg = &Message{
Payload: payload,
RequestID: id,
TTL: choria.Config.TTL,
DiscoveredHosts: []string{},
SenderID: choria.Config.Identity,
CallerID: choria.CallerID(),
Filter: protocol.NewFilter(),
choria: choria,
}
err = msg.SetType(msgType)
if err != nil {
return
}
if request == nil {
msg.Agent = agent
err = msg.SetCollective(collective)
if err != nil {
return
}
} else {
msg.Request = request
msg.Agent = request.Agent
msg.replyTo = request.ReplyTo()
msg.SetType("reply")
err = msg.SetCollective(request.collective)
if err != nil {
return
}
}
_, err = msg.Validate()
return
} | go | func NewMessage(payload string, agent string, collective string, msgType string, request *Message, choria *Framework) (msg *Message, err error) {
id, err := choria.NewRequestID()
if err != nil {
return
}
msg = &Message{
Payload: payload,
RequestID: id,
TTL: choria.Config.TTL,
DiscoveredHosts: []string{},
SenderID: choria.Config.Identity,
CallerID: choria.CallerID(),
Filter: protocol.NewFilter(),
choria: choria,
}
err = msg.SetType(msgType)
if err != nil {
return
}
if request == nil {
msg.Agent = agent
err = msg.SetCollective(collective)
if err != nil {
return
}
} else {
msg.Request = request
msg.Agent = request.Agent
msg.replyTo = request.ReplyTo()
msg.SetType("reply")
err = msg.SetCollective(request.collective)
if err != nil {
return
}
}
_, err = msg.Validate()
return
} | [
"func",
"NewMessage",
"(",
"payload",
"string",
",",
"agent",
"string",
",",
"collective",
"string",
",",
"msgType",
"string",
",",
"request",
"*",
"Message",
",",
"choria",
"*",
"Framework",
")",
"(",
"msg",
"*",
"Message",
",",
"err",
"error",
")",
"{"... | // NewMessage constructs a basic Message instance | [
"NewMessage",
"constructs",
"a",
"basic",
"Message",
"instance"
] | 2c773ed36498f426852fd294ebb832c6a2625eba | https://github.com/choria-io/go-choria/blob/2c773ed36498f426852fd294ebb832c6a2625eba/choria/message.go#L67-L109 |
15,902 | choria-io/go-choria | choria/message.go | Validate | func (msg *Message) Validate() (bool, error) {
if msg.Agent == "" {
return false, fmt.Errorf("agent has not been set")
}
if msg.collective == "" {
return false, fmt.Errorf("collective has not been set")
}
if !msg.choria.HasCollective(msg.collective) {
return false, fmt.Errorf("'%s' is not on the list of known collectives", msg.collective)
}
return true, nil
} | go | func (msg *Message) Validate() (bool, error) {
if msg.Agent == "" {
return false, fmt.Errorf("agent has not been set")
}
if msg.collective == "" {
return false, fmt.Errorf("collective has not been set")
}
if !msg.choria.HasCollective(msg.collective) {
return false, fmt.Errorf("'%s' is not on the list of known collectives", msg.collective)
}
return true, nil
} | [
"func",
"(",
"msg",
"*",
"Message",
")",
"Validate",
"(",
")",
"(",
"bool",
",",
"error",
")",
"{",
"if",
"msg",
".",
"Agent",
"==",
"\"",
"\"",
"{",
"return",
"false",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
... | // Validate tests the Message and makes sure its settings are sane | [
"Validate",
"tests",
"the",
"Message",
"and",
"makes",
"sure",
"its",
"settings",
"are",
"sane"
] | 2c773ed36498f426852fd294ebb832c6a2625eba | https://github.com/choria-io/go-choria/blob/2c773ed36498f426852fd294ebb832c6a2625eba/choria/message.go#L162-L176 |
15,903 | choria-io/go-choria | choria/message.go | ValidateTTL | func (msg *Message) ValidateTTL() bool {
now := time.Now()
earliest := now.Add(-1 * time.Duration(msg.TTL) * time.Second)
latest := now.Add(time.Duration(msg.TTL) * time.Second)
return msg.TimeStamp.Before(latest) && msg.TimeStamp.After(earliest)
} | go | func (msg *Message) ValidateTTL() bool {
now := time.Now()
earliest := now.Add(-1 * time.Duration(msg.TTL) * time.Second)
latest := now.Add(time.Duration(msg.TTL) * time.Second)
return msg.TimeStamp.Before(latest) && msg.TimeStamp.After(earliest)
} | [
"func",
"(",
"msg",
"*",
"Message",
")",
"ValidateTTL",
"(",
")",
"bool",
"{",
"now",
":=",
"time",
".",
"Now",
"(",
")",
"\n",
"earliest",
":=",
"now",
".",
"Add",
"(",
"-",
"1",
"*",
"time",
".",
"Duration",
"(",
"msg",
".",
"TTL",
")",
"*",
... | // ValidateTTL validates the message age, true if the message should be allowed | [
"ValidateTTL",
"validates",
"the",
"message",
"age",
"true",
"if",
"the",
"message",
"should",
"be",
"allowed"
] | 2c773ed36498f426852fd294ebb832c6a2625eba | https://github.com/choria-io/go-choria/blob/2c773ed36498f426852fd294ebb832c6a2625eba/choria/message.go#L179-L185 |
15,904 | choria-io/go-choria | choria/message.go | SetBase64Payload | func (msg *Message) SetBase64Payload(payload string) error {
str, err := base64.StdEncoding.DecodeString(payload)
if err != nil {
return fmt.Errorf("could not decode supplied payload using base64: %s", err)
}
msg.Payload = string(str)
return nil
} | go | func (msg *Message) SetBase64Payload(payload string) error {
str, err := base64.StdEncoding.DecodeString(payload)
if err != nil {
return fmt.Errorf("could not decode supplied payload using base64: %s", err)
}
msg.Payload = string(str)
return nil
} | [
"func",
"(",
"msg",
"*",
"Message",
")",
"SetBase64Payload",
"(",
"payload",
"string",
")",
"error",
"{",
"str",
",",
"err",
":=",
"base64",
".",
"StdEncoding",
".",
"DecodeString",
"(",
"payload",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"f... | // SetBase64Payload sets the payload for the message, use it if the payload is Base64 encoded | [
"SetBase64Payload",
"sets",
"the",
"payload",
"for",
"the",
"message",
"use",
"it",
"if",
"the",
"payload",
"is",
"Base64",
"encoded"
] | 2c773ed36498f426852fd294ebb832c6a2625eba | https://github.com/choria-io/go-choria/blob/2c773ed36498f426852fd294ebb832c6a2625eba/choria/message.go#L188-L197 |
15,905 | choria-io/go-choria | choria/message.go | Base64Payload | func (msg *Message) Base64Payload() string {
return base64.StdEncoding.EncodeToString([]byte(msg.Payload))
} | go | func (msg *Message) Base64Payload() string {
return base64.StdEncoding.EncodeToString([]byte(msg.Payload))
} | [
"func",
"(",
"msg",
"*",
"Message",
")",
"Base64Payload",
"(",
")",
"string",
"{",
"return",
"base64",
".",
"StdEncoding",
".",
"EncodeToString",
"(",
"[",
"]",
"byte",
"(",
"msg",
".",
"Payload",
")",
")",
"\n",
"}"
] | // Base64Payload retrieves the payload Base64 encoded | [
"Base64Payload",
"retrieves",
"the",
"payload",
"Base64",
"encoded"
] | 2c773ed36498f426852fd294ebb832c6a2625eba | https://github.com/choria-io/go-choria/blob/2c773ed36498f426852fd294ebb832c6a2625eba/choria/message.go#L200-L202 |
15,906 | choria-io/go-choria | choria/message.go | SetExpectedMsgID | func (msg *Message) SetExpectedMsgID(id string) error {
if msg.Type() != "reply" {
return fmt.Errorf("can only store expected message ID for reply messages")
}
msg.expectedMessageID = id
return nil
} | go | func (msg *Message) SetExpectedMsgID(id string) error {
if msg.Type() != "reply" {
return fmt.Errorf("can only store expected message ID for reply messages")
}
msg.expectedMessageID = id
return nil
} | [
"func",
"(",
"msg",
"*",
"Message",
")",
"SetExpectedMsgID",
"(",
"id",
"string",
")",
"error",
"{",
"if",
"msg",
".",
"Type",
"(",
")",
"!=",
"\"",
"\"",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"msg",
".",
... | // SetExpectedMsgID sets the Request ID that is expected from the reply data | [
"SetExpectedMsgID",
"sets",
"the",
"Request",
"ID",
"that",
"is",
"expected",
"from",
"the",
"reply",
"data"
] | 2c773ed36498f426852fd294ebb832c6a2625eba | https://github.com/choria-io/go-choria/blob/2c773ed36498f426852fd294ebb832c6a2625eba/choria/message.go#L205-L213 |
15,907 | choria-io/go-choria | choria/message.go | SetReplyTo | func (msg *Message) SetReplyTo(replyTo string) error {
if !(msg.Type() == "request" || msg.Type() == "direct_request") {
return fmt.Errorf("custom reply to targets can only be set for requests")
}
msg.replyTo = replyTo
return nil
} | go | func (msg *Message) SetReplyTo(replyTo string) error {
if !(msg.Type() == "request" || msg.Type() == "direct_request") {
return fmt.Errorf("custom reply to targets can only be set for requests")
}
msg.replyTo = replyTo
return nil
} | [
"func",
"(",
"msg",
"*",
"Message",
")",
"SetReplyTo",
"(",
"replyTo",
"string",
")",
"error",
"{",
"if",
"!",
"(",
"msg",
".",
"Type",
"(",
")",
"==",
"\"",
"\"",
"||",
"msg",
".",
"Type",
"(",
")",
"==",
"\"",
"\"",
")",
"{",
"return",
"fmt",... | // SetReplyTo sets the NATS target where replies to this message should go | [
"SetReplyTo",
"sets",
"the",
"NATS",
"target",
"where",
"replies",
"to",
"this",
"message",
"should",
"go"
] | 2c773ed36498f426852fd294ebb832c6a2625eba | https://github.com/choria-io/go-choria/blob/2c773ed36498f426852fd294ebb832c6a2625eba/choria/message.go#L221-L229 |
15,908 | choria-io/go-choria | choria/message.go | SetCollective | func (msg *Message) SetCollective(collective string) error {
if !msg.choria.HasCollective(collective) {
return fmt.Errorf("cannot set collective to '%s', it is not on the list of known collectives", collective)
}
msg.collective = collective
return nil
} | go | func (msg *Message) SetCollective(collective string) error {
if !msg.choria.HasCollective(collective) {
return fmt.Errorf("cannot set collective to '%s', it is not on the list of known collectives", collective)
}
msg.collective = collective
return nil
} | [
"func",
"(",
"msg",
"*",
"Message",
")",
"SetCollective",
"(",
"collective",
"string",
")",
"error",
"{",
"if",
"!",
"msg",
".",
"choria",
".",
"HasCollective",
"(",
"collective",
")",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"collect... | // SetCollective sets the sub collective this message is targeting | [
"SetCollective",
"sets",
"the",
"sub",
"collective",
"this",
"message",
"is",
"targeting"
] | 2c773ed36498f426852fd294ebb832c6a2625eba | https://github.com/choria-io/go-choria/blob/2c773ed36498f426852fd294ebb832c6a2625eba/choria/message.go#L237-L245 |
15,909 | choria-io/go-choria | choria/message.go | SetType | func (msg *Message) SetType(msgType string) (err error) {
if !(msgType == "message" || msgType == "request" || msgType == "direct_request" || msgType == "reply") {
return fmt.Errorf("%s is not a valid message type", msgType)
}
if msgType == "direct_request" {
if len(msg.DiscoveredHosts) == 0 {
return fmt.Errorf("direct_request message type can only be set if DiscoveredHosts have been set")
}
msg.Filter = protocol.NewFilter()
msg.Filter.AddAgentFilter(msg.Agent)
}
msg.msgType = msgType
return
} | go | func (msg *Message) SetType(msgType string) (err error) {
if !(msgType == "message" || msgType == "request" || msgType == "direct_request" || msgType == "reply") {
return fmt.Errorf("%s is not a valid message type", msgType)
}
if msgType == "direct_request" {
if len(msg.DiscoveredHosts) == 0 {
return fmt.Errorf("direct_request message type can only be set if DiscoveredHosts have been set")
}
msg.Filter = protocol.NewFilter()
msg.Filter.AddAgentFilter(msg.Agent)
}
msg.msgType = msgType
return
} | [
"func",
"(",
"msg",
"*",
"Message",
")",
"SetType",
"(",
"msgType",
"string",
")",
"(",
"err",
"error",
")",
"{",
"if",
"!",
"(",
"msgType",
"==",
"\"",
"\"",
"||",
"msgType",
"==",
"\"",
"\"",
"||",
"msgType",
"==",
"\"",
"\"",
"||",
"msgType",
... | // SetType sets the mssage type. One message, request, direct_request or reply | [
"SetType",
"sets",
"the",
"mssage",
"type",
".",
"One",
"message",
"request",
"direct_request",
"or",
"reply"
] | 2c773ed36498f426852fd294ebb832c6a2625eba | https://github.com/choria-io/go-choria/blob/2c773ed36498f426852fd294ebb832c6a2625eba/choria/message.go#L253-L270 |
15,910 | choria-io/go-choria | choria/message.go | String | func (msg *Message) String() string {
return fmt.Sprintf("%s from %s@%s for agent %s", msg.RequestID, msg.CallerID, msg.SenderID, msg.Agent)
} | go | func (msg *Message) String() string {
return fmt.Sprintf("%s from %s@%s for agent %s", msg.RequestID, msg.CallerID, msg.SenderID, msg.Agent)
} | [
"func",
"(",
"msg",
"*",
"Message",
")",
"String",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"msg",
".",
"RequestID",
",",
"msg",
".",
"CallerID",
",",
"msg",
".",
"SenderID",
",",
"msg",
".",
"Agent",
")",
"... | // String creates a string representation of the message for logs etc | [
"String",
"creates",
"a",
"string",
"representation",
"of",
"the",
"message",
"for",
"logs",
"etc"
] | 2c773ed36498f426852fd294ebb832c6a2625eba | https://github.com/choria-io/go-choria/blob/2c773ed36498f426852fd294ebb832c6a2625eba/choria/message.go#L278-L280 |
15,911 | choria-io/go-choria | choria/connection.go | NewConnector | func (fw *Framework) NewConnector(ctx context.Context, servers func() ([]srvcache.Server, error), name string, logger *log.Entry) (conn Connector, err error) {
if name == "" {
name = fw.Config.Identity
}
conn = &Connection{
name: name,
servers: servers,
logger: logger.WithField("connection", name),
choria: fw,
config: fw.Config,
subscriptions: make(map[string]*nats.Subscription),
chanSubscriptions: make(map[string]*channelSubscription),
outbox: make(chan *nats.Msg, 1000),
}
err = conn.Connect(ctx)
return conn, err
} | go | func (fw *Framework) NewConnector(ctx context.Context, servers func() ([]srvcache.Server, error), name string, logger *log.Entry) (conn Connector, err error) {
if name == "" {
name = fw.Config.Identity
}
conn = &Connection{
name: name,
servers: servers,
logger: logger.WithField("connection", name),
choria: fw,
config: fw.Config,
subscriptions: make(map[string]*nats.Subscription),
chanSubscriptions: make(map[string]*channelSubscription),
outbox: make(chan *nats.Msg, 1000),
}
err = conn.Connect(ctx)
return conn, err
} | [
"func",
"(",
"fw",
"*",
"Framework",
")",
"NewConnector",
"(",
"ctx",
"context",
".",
"Context",
",",
"servers",
"func",
"(",
")",
"(",
"[",
"]",
"srvcache",
".",
"Server",
",",
"error",
")",
",",
"name",
"string",
",",
"logger",
"*",
"log",
".",
"... | // NewConnector creates a new NATS connector
//
// It will attempt to connect to the given servers and will keep trying till it manages to do so | [
"NewConnector",
"creates",
"a",
"new",
"NATS",
"connector",
"It",
"will",
"attempt",
"to",
"connect",
"to",
"the",
"given",
"servers",
"and",
"will",
"keep",
"trying",
"till",
"it",
"manages",
"to",
"do",
"so"
] | 2c773ed36498f426852fd294ebb832c6a2625eba | https://github.com/choria-io/go-choria/blob/2c773ed36498f426852fd294ebb832c6a2625eba/choria/connection.go#L150-L169 |
15,912 | choria-io/go-choria | choria/connection.go | ChanQueueSubscribe | func (conn *Connection) ChanQueueSubscribe(name string, subject string, group string, capacity int) (chan *ConnectorMessage, error) {
var err error
s := &channelSubscription{
in: make(chan *nats.Msg, capacity),
out: make(chan *ConnectorMessage, capacity),
quit: make(chan interface{}, 1),
}
conn.subMu.Lock()
conn.chanSubscriptions[name] = s
conn.subMu.Unlock()
copier := func(subs *channelSubscription) {
for {
select {
case m := <-subs.in:
subs.out <- &ConnectorMessage{Data: m.Data, Reply: m.Reply, Subject: m.Subject}
case <-subs.quit:
return
}
}
}
go copier(s)
conn.logger.Debugf("Subscribing to %s in group '%s' on server %s", subject, group, conn.ConnectedServer())
s.subscription, err = conn.nats.ChanQueueSubscribe(subject, group, s.in)
if err != nil {
return nil, fmt.Errorf("Could not subscribe to subscription %s: %s", name, err)
}
return s.out, nil
} | go | func (conn *Connection) ChanQueueSubscribe(name string, subject string, group string, capacity int) (chan *ConnectorMessage, error) {
var err error
s := &channelSubscription{
in: make(chan *nats.Msg, capacity),
out: make(chan *ConnectorMessage, capacity),
quit: make(chan interface{}, 1),
}
conn.subMu.Lock()
conn.chanSubscriptions[name] = s
conn.subMu.Unlock()
copier := func(subs *channelSubscription) {
for {
select {
case m := <-subs.in:
subs.out <- &ConnectorMessage{Data: m.Data, Reply: m.Reply, Subject: m.Subject}
case <-subs.quit:
return
}
}
}
go copier(s)
conn.logger.Debugf("Subscribing to %s in group '%s' on server %s", subject, group, conn.ConnectedServer())
s.subscription, err = conn.nats.ChanQueueSubscribe(subject, group, s.in)
if err != nil {
return nil, fmt.Errorf("Could not subscribe to subscription %s: %s", name, err)
}
return s.out, nil
} | [
"func",
"(",
"conn",
"*",
"Connection",
")",
"ChanQueueSubscribe",
"(",
"name",
"string",
",",
"subject",
"string",
",",
"group",
"string",
",",
"capacity",
"int",
")",
"(",
"chan",
"*",
"ConnectorMessage",
",",
"error",
")",
"{",
"var",
"err",
"error",
... | // ChanQueueSubscribe creates a channel of a certain size and subscribes to a queue group.
//
// The given name would later be used should a unsubscribe be needed | [
"ChanQueueSubscribe",
"creates",
"a",
"channel",
"of",
"a",
"certain",
"size",
"and",
"subscribes",
"to",
"a",
"queue",
"group",
".",
"The",
"given",
"name",
"would",
"later",
"be",
"used",
"should",
"a",
"unsubscribe",
"be",
"needed"
] | 2c773ed36498f426852fd294ebb832c6a2625eba | https://github.com/choria-io/go-choria/blob/2c773ed36498f426852fd294ebb832c6a2625eba/choria/connection.go#L186-L220 |
15,913 | choria-io/go-choria | choria/connection.go | QueueSubscribe | func (conn *Connection) QueueSubscribe(ctx context.Context, name string, subject string, group string, output chan *ConnectorMessage) error {
var err error
s := &channelSubscription{
in: make(chan *nats.Msg, cap(output)),
out: output,
quit: make(chan interface{}, 1),
}
conn.subMu.Lock()
conn.chanSubscriptions[name] = s
conn.subMu.Unlock()
copier := func(ctx context.Context, s *channelSubscription) {
for {
select {
case m := <-s.in:
s.out <- &ConnectorMessage{Data: m.Data, Reply: m.Reply, Subject: m.Subject}
case <-ctx.Done():
conn.Unsubscribe(name)
return
case <-s.quit:
close(s.in)
return
}
}
}
go copier(ctx, s)
conn.logger.Debugf("Subscribing to %s in group '%s' on server %s", subject, group, conn.ConnectedServer())
s.subscription, err = conn.nats.ChanQueueSubscribe(subject, group, s.in)
if err != nil {
return fmt.Errorf("Could not subscribe to subscription %s: %s", name, err)
}
return err
} | go | func (conn *Connection) QueueSubscribe(ctx context.Context, name string, subject string, group string, output chan *ConnectorMessage) error {
var err error
s := &channelSubscription{
in: make(chan *nats.Msg, cap(output)),
out: output,
quit: make(chan interface{}, 1),
}
conn.subMu.Lock()
conn.chanSubscriptions[name] = s
conn.subMu.Unlock()
copier := func(ctx context.Context, s *channelSubscription) {
for {
select {
case m := <-s.in:
s.out <- &ConnectorMessage{Data: m.Data, Reply: m.Reply, Subject: m.Subject}
case <-ctx.Done():
conn.Unsubscribe(name)
return
case <-s.quit:
close(s.in)
return
}
}
}
go copier(ctx, s)
conn.logger.Debugf("Subscribing to %s in group '%s' on server %s", subject, group, conn.ConnectedServer())
s.subscription, err = conn.nats.ChanQueueSubscribe(subject, group, s.in)
if err != nil {
return fmt.Errorf("Could not subscribe to subscription %s: %s", name, err)
}
return err
} | [
"func",
"(",
"conn",
"*",
"Connection",
")",
"QueueSubscribe",
"(",
"ctx",
"context",
".",
"Context",
",",
"name",
"string",
",",
"subject",
"string",
",",
"group",
"string",
",",
"output",
"chan",
"*",
"ConnectorMessage",
")",
"error",
"{",
"var",
"err",
... | // QueueSubscribe is a lot like ChanQueueSubscribe but you provide it the queue to dump messages in,
// it also takes a context and will unsubscribe when the context is cancelled | [
"QueueSubscribe",
"is",
"a",
"lot",
"like",
"ChanQueueSubscribe",
"but",
"you",
"provide",
"it",
"the",
"queue",
"to",
"dump",
"messages",
"in",
"it",
"also",
"takes",
"a",
"context",
"and",
"will",
"unsubscribe",
"when",
"the",
"context",
"is",
"cancelled"
] | 2c773ed36498f426852fd294ebb832c6a2625eba | https://github.com/choria-io/go-choria/blob/2c773ed36498f426852fd294ebb832c6a2625eba/choria/connection.go#L224-L262 |
15,914 | choria-io/go-choria | choria/connection.go | PublishRaw | func (conn *Connection) PublishRaw(target string, data []byte) error {
log.Debugf("Publishing %d bytes to %s", len(data), target)
return conn.nats.Publish(target, data)
} | go | func (conn *Connection) PublishRaw(target string, data []byte) error {
log.Debugf("Publishing %d bytes to %s", len(data), target)
return conn.nats.Publish(target, data)
} | [
"func",
"(",
"conn",
"*",
"Connection",
")",
"PublishRaw",
"(",
"target",
"string",
",",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"log",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"len",
"(",
"data",
")",
",",
"target",
")",
"\n\n",
"return",
"conn",... | // PublishRaw allows any data to be published to any target | [
"PublishRaw",
"allows",
"any",
"data",
"to",
"be",
"published",
"to",
"any",
"target"
] | 2c773ed36498f426852fd294ebb832c6a2625eba | https://github.com/choria-io/go-choria/blob/2c773ed36498f426852fd294ebb832c6a2625eba/choria/connection.go#L290-L294 |
15,915 | choria-io/go-choria | choria/connection.go | Publish | func (conn *Connection) Publish(msg *Message) error {
transport, err := msg.Transport()
if err != nil {
return fmt.Errorf("Cannot publish Message %s: %s", msg.RequestID, err)
}
transport.RecordNetworkHop(conn.ConnectedServer(), conn.choria.Config.Identity, conn.ConnectedServer())
if msg.CustomTarget != "" {
return conn.publishConnectedBroadcast(msg, transport)
}
if conn.choria.IsFederated() {
return conn.publishFederated(msg, transport)
}
return conn.publishConnected(msg, transport)
} | go | func (conn *Connection) Publish(msg *Message) error {
transport, err := msg.Transport()
if err != nil {
return fmt.Errorf("Cannot publish Message %s: %s", msg.RequestID, err)
}
transport.RecordNetworkHop(conn.ConnectedServer(), conn.choria.Config.Identity, conn.ConnectedServer())
if msg.CustomTarget != "" {
return conn.publishConnectedBroadcast(msg, transport)
}
if conn.choria.IsFederated() {
return conn.publishFederated(msg, transport)
}
return conn.publishConnected(msg, transport)
} | [
"func",
"(",
"conn",
"*",
"Connection",
")",
"Publish",
"(",
"msg",
"*",
"Message",
")",
"error",
"{",
"transport",
",",
"err",
":=",
"msg",
".",
"Transport",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",... | // Publish inspects a Message and publish it according to its Type | [
"Publish",
"inspects",
"a",
"Message",
"and",
"publish",
"it",
"according",
"to",
"its",
"Type"
] | 2c773ed36498f426852fd294ebb832c6a2625eba | https://github.com/choria-io/go-choria/blob/2c773ed36498f426852fd294ebb832c6a2625eba/choria/connection.go#L297-L314 |
15,916 | choria-io/go-choria | choria/connection.go | ConnectedServer | func (conn *Connection) ConnectedServer() string {
if conn.Nats() == nil {
return "unknown"
}
url, err := url.Parse(conn.nats.ConnectedUrl())
if err != nil {
return "unknown"
}
return fmt.Sprintf("nats://%s:%s", strings.TrimSuffix(url.Hostname(), "."), url.Port())
} | go | func (conn *Connection) ConnectedServer() string {
if conn.Nats() == nil {
return "unknown"
}
url, err := url.Parse(conn.nats.ConnectedUrl())
if err != nil {
return "unknown"
}
return fmt.Sprintf("nats://%s:%s", strings.TrimSuffix(url.Hostname(), "."), url.Port())
} | [
"func",
"(",
"conn",
"*",
"Connection",
")",
"ConnectedServer",
"(",
")",
"string",
"{",
"if",
"conn",
".",
"Nats",
"(",
")",
"==",
"nil",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n\n",
"url",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"conn",
".... | // ConnectedServer returns the URL of the current server that the library is connected to, "unknown" when not initialized | [
"ConnectedServer",
"returns",
"the",
"URL",
"of",
"the",
"current",
"server",
"that",
"the",
"library",
"is",
"connected",
"to",
"unknown",
"when",
"not",
"initialized"
] | 2c773ed36498f426852fd294ebb832c6a2625eba | https://github.com/choria-io/go-choria/blob/2c773ed36498f426852fd294ebb832c6a2625eba/choria/connection.go#L502-L513 |
15,917 | choria-io/go-choria | choria/connection.go | Close | func (conn *Connection) Close() {
subs := []string{}
conn.subMu.Lock()
for s := range conn.chanSubscriptions {
subs = append(subs, s)
}
for s := range conn.subscriptions {
subs = append(subs, s)
}
conn.subMu.Unlock()
for _, s := range subs {
err := conn.Unsubscribe(s)
if err != nil {
conn.logger.Warnf("Could not unsubscribe from %s: %s", s, err)
}
}
conn.Flush()
conn.conMu.Lock()
defer conn.conMu.Unlock()
conn.logger.Debug("Closing NATS connection")
conn.nats.Close()
} | go | func (conn *Connection) Close() {
subs := []string{}
conn.subMu.Lock()
for s := range conn.chanSubscriptions {
subs = append(subs, s)
}
for s := range conn.subscriptions {
subs = append(subs, s)
}
conn.subMu.Unlock()
for _, s := range subs {
err := conn.Unsubscribe(s)
if err != nil {
conn.logger.Warnf("Could not unsubscribe from %s: %s", s, err)
}
}
conn.Flush()
conn.conMu.Lock()
defer conn.conMu.Unlock()
conn.logger.Debug("Closing NATS connection")
conn.nats.Close()
} | [
"func",
"(",
"conn",
"*",
"Connection",
")",
"Close",
"(",
")",
"{",
"subs",
":=",
"[",
"]",
"string",
"{",
"}",
"\n\n",
"conn",
".",
"subMu",
".",
"Lock",
"(",
")",
"\n\n",
"for",
"s",
":=",
"range",
"conn",
".",
"chanSubscriptions",
"{",
"subs",
... | // Close closes the NATS connection after flushing what needed to be sent | [
"Close",
"closes",
"the",
"NATS",
"connection",
"after",
"flushing",
"what",
"needed",
"to",
"be",
"sent"
] | 2c773ed36498f426852fd294ebb832c6a2625eba | https://github.com/choria-io/go-choria/blob/2c773ed36498f426852fd294ebb832c6a2625eba/choria/connection.go#L637-L667 |
15,918 | choria-io/go-choria | aagent/machine/info.go | UniqueID | func (m *Machine) UniqueID() (id string) {
uuid, err := uuid.NewV4()
if err == nil {
return uuid.String()
}
parts := []string{}
parts = append(parts, randStringRunes(8))
parts = append(parts, randStringRunes(4))
parts = append(parts, randStringRunes(4))
parts = append(parts, randStringRunes(12))
return strings.Join(parts, "-")
} | go | func (m *Machine) UniqueID() (id string) {
uuid, err := uuid.NewV4()
if err == nil {
return uuid.String()
}
parts := []string{}
parts = append(parts, randStringRunes(8))
parts = append(parts, randStringRunes(4))
parts = append(parts, randStringRunes(4))
parts = append(parts, randStringRunes(12))
return strings.Join(parts, "-")
} | [
"func",
"(",
"m",
"*",
"Machine",
")",
"UniqueID",
"(",
")",
"(",
"id",
"string",
")",
"{",
"uuid",
",",
"err",
":=",
"uuid",
".",
"NewV4",
"(",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"return",
"uuid",
".",
"String",
"(",
")",
"\n",
"}",
"... | // UniqueID creates a new unique ID, usually a v4 uuid, if that fails a random string based ID is made | [
"UniqueID",
"creates",
"a",
"new",
"unique",
"ID",
"usually",
"a",
"v4",
"uuid",
"if",
"that",
"fails",
"a",
"random",
"string",
"based",
"ID",
"is",
"made"
] | 2c773ed36498f426852fd294ebb832c6a2625eba | https://github.com/choria-io/go-choria/blob/2c773ed36498f426852fd294ebb832c6a2625eba/aagent/machine/info.go#L71-L84 |
15,919 | choria-io/go-choria | server/additional_agents.go | RegisterAdditionalAgent | func RegisterAdditionalAgent(i AgentInitializer) {
aamu.Lock()
defer aamu.Unlock()
additionalAgents = append(additionalAgents, i)
} | go | func RegisterAdditionalAgent(i AgentInitializer) {
aamu.Lock()
defer aamu.Unlock()
additionalAgents = append(additionalAgents, i)
} | [
"func",
"RegisterAdditionalAgent",
"(",
"i",
"AgentInitializer",
")",
"{",
"aamu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"aamu",
".",
"Unlock",
"(",
")",
"\n\n",
"additionalAgents",
"=",
"append",
"(",
"additionalAgents",
",",
"i",
")",
"\n",
"}"
] | // RegisterAdditionalAgent adds an agent to a running server
// this should be used for compile time injection of agents
// other than the ones that ship with choria | [
"RegisterAdditionalAgent",
"adds",
"an",
"agent",
"to",
"a",
"running",
"server",
"this",
"should",
"be",
"used",
"for",
"compile",
"time",
"injection",
"of",
"agents",
"other",
"than",
"the",
"ones",
"that",
"ship",
"with",
"choria"
] | 2c773ed36498f426852fd294ebb832c6a2625eba | https://github.com/choria-io/go-choria/blob/2c773ed36498f426852fd294ebb832c6a2625eba/server/additional_agents.go#L26-L31 |
15,920 | choria-io/go-choria | config/util.go | DNSFQDN | func DNSFQDN() (string, error) {
hostname, err := os.Hostname()
if err != nil {
return "", err
}
addrs, err := net.LookupIP(hostname)
if err != nil {
return "", err
}
for _, addr := range addrs {
if ipv4 := addr.To4(); ipv4 != nil {
ip, err := ipv4.MarshalText()
if err != nil {
return "", err
}
hosts, err := net.LookupAddr(string(ip))
if err != nil || len(hosts) == 0 {
return "", err
}
fqdn := hosts[0]
// return fqdn without trailing dot
return strings.TrimSuffix(fqdn, "."), nil
}
}
return "", fmt.Errorf("could not resolve FQDN using DNS")
} | go | func DNSFQDN() (string, error) {
hostname, err := os.Hostname()
if err != nil {
return "", err
}
addrs, err := net.LookupIP(hostname)
if err != nil {
return "", err
}
for _, addr := range addrs {
if ipv4 := addr.To4(); ipv4 != nil {
ip, err := ipv4.MarshalText()
if err != nil {
return "", err
}
hosts, err := net.LookupAddr(string(ip))
if err != nil || len(hosts) == 0 {
return "", err
}
fqdn := hosts[0]
// return fqdn without trailing dot
return strings.TrimSuffix(fqdn, "."), nil
}
}
return "", fmt.Errorf("could not resolve FQDN using DNS")
} | [
"func",
"DNSFQDN",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"hostname",
",",
"err",
":=",
"os",
".",
"Hostname",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"addrs",
",",
"err",
":... | // DNSFQDN attempts to find the FQDN using DNS resolution | [
"DNSFQDN",
"attempts",
"to",
"find",
"the",
"FQDN",
"using",
"DNS",
"resolution"
] | 2c773ed36498f426852fd294ebb832c6a2625eba | https://github.com/choria-io/go-choria/blob/2c773ed36498f426852fd294ebb832c6a2625eba/config/util.go#L11-L42 |
15,921 | choria-io/go-choria | server/lifecycle.go | PublishEvent | func (srv *Instance) PublishEvent(e lifecycle.Event) error {
return lifecycle.PublishEvent(e, srv.connector)
} | go | func (srv *Instance) PublishEvent(e lifecycle.Event) error {
return lifecycle.PublishEvent(e, srv.connector)
} | [
"func",
"(",
"srv",
"*",
"Instance",
")",
"PublishEvent",
"(",
"e",
"lifecycle",
".",
"Event",
")",
"error",
"{",
"return",
"lifecycle",
".",
"PublishEvent",
"(",
"e",
",",
"srv",
".",
"connector",
")",
"\n",
"}"
] | // PublishEvent publishes a lifecycle event to the network | [
"PublishEvent",
"publishes",
"a",
"lifecycle",
"event",
"to",
"the",
"network"
] | 2c773ed36498f426852fd294ebb832c6a2625eba | https://github.com/choria-io/go-choria/blob/2c773ed36498f426852fd294ebb832c6a2625eba/server/lifecycle.go#L20-L22 |
15,922 | choria-io/go-choria | aagent/machine/machine.go | FromYAML | func FromYAML(file string, manager WatcherManager) (m *Machine, err error) {
afile, err := filepath.Abs(file)
if err != nil {
return nil, errors.Wrapf(err, "could not determine absolute path for %s", file)
}
f, err := ioutil.ReadFile(afile)
if err != nil {
return nil, err
}
m = &Machine{}
err = yaml.Unmarshal(f, m)
if err != nil {
return nil, err
}
m.notifiers = []NotificationService{}
m.manager = manager
m.directory = filepath.Dir(afile)
m.manifest = afile
m.instanceID = m.UniqueID()
err = m.manager.SetMachine(m)
if err != nil {
return nil, errors.Wrap(err, "could not register with manager")
}
err = m.Setup()
if err != nil {
return nil, err
}
return m, nil
} | go | func FromYAML(file string, manager WatcherManager) (m *Machine, err error) {
afile, err := filepath.Abs(file)
if err != nil {
return nil, errors.Wrapf(err, "could not determine absolute path for %s", file)
}
f, err := ioutil.ReadFile(afile)
if err != nil {
return nil, err
}
m = &Machine{}
err = yaml.Unmarshal(f, m)
if err != nil {
return nil, err
}
m.notifiers = []NotificationService{}
m.manager = manager
m.directory = filepath.Dir(afile)
m.manifest = afile
m.instanceID = m.UniqueID()
err = m.manager.SetMachine(m)
if err != nil {
return nil, errors.Wrap(err, "could not register with manager")
}
err = m.Setup()
if err != nil {
return nil, err
}
return m, nil
} | [
"func",
"FromYAML",
"(",
"file",
"string",
",",
"manager",
"WatcherManager",
")",
"(",
"m",
"*",
"Machine",
",",
"err",
"error",
")",
"{",
"afile",
",",
"err",
":=",
"filepath",
".",
"Abs",
"(",
"file",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"re... | // FromYAML loads a macine from a YAML definition | [
"FromYAML",
"loads",
"a",
"macine",
"from",
"a",
"YAML",
"definition"
] | 2c773ed36498f426852fd294ebb832c6a2625eba | https://github.com/choria-io/go-choria/blob/2c773ed36498f426852fd294ebb832c6a2625eba/aagent/machine/machine.go#L101-L135 |
15,923 | choria-io/go-choria | aagent/machine/machine.go | ValidateDir | func ValidateDir(dir string) (validationErrors []string, err error) {
mpath := yamlPath(dir)
yml, err := ioutil.ReadFile(mpath)
if err != nil {
return nil, err
}
jbytes, err := yaml.YAMLToJSON(yml)
if err != nil {
return nil, errors.Wrap(err, "could not transform YAML to JSON")
}
schemaLoader := gojsonschema.NewReferenceLoader("https://choria.io/schemas/choria/machine/v1/manifest.json")
documentLoader := gojsonschema.NewBytesLoader(jbytes)
result, err := gojsonschema.Validate(schemaLoader, documentLoader)
if err != nil {
return nil, errors.Wrapf(err, "could not perform schema validation")
}
if result.Valid() {
return []string{}, nil
}
validationErrors = []string{}
for _, desc := range result.Errors() {
validationErrors = append(validationErrors, desc.String())
}
return validationErrors, nil
} | go | func ValidateDir(dir string) (validationErrors []string, err error) {
mpath := yamlPath(dir)
yml, err := ioutil.ReadFile(mpath)
if err != nil {
return nil, err
}
jbytes, err := yaml.YAMLToJSON(yml)
if err != nil {
return nil, errors.Wrap(err, "could not transform YAML to JSON")
}
schemaLoader := gojsonschema.NewReferenceLoader("https://choria.io/schemas/choria/machine/v1/manifest.json")
documentLoader := gojsonschema.NewBytesLoader(jbytes)
result, err := gojsonschema.Validate(schemaLoader, documentLoader)
if err != nil {
return nil, errors.Wrapf(err, "could not perform schema validation")
}
if result.Valid() {
return []string{}, nil
}
validationErrors = []string{}
for _, desc := range result.Errors() {
validationErrors = append(validationErrors, desc.String())
}
return validationErrors, nil
} | [
"func",
"ValidateDir",
"(",
"dir",
"string",
")",
"(",
"validationErrors",
"[",
"]",
"string",
",",
"err",
"error",
")",
"{",
"mpath",
":=",
"yamlPath",
"(",
"dir",
")",
"\n",
"yml",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"mpath",
")",
"\n... | // ValidateDir validates a machine.yaml against the v1 schema | [
"ValidateDir",
"validates",
"a",
"machine",
".",
"yaml",
"against",
"the",
"v1",
"schema"
] | 2c773ed36498f426852fd294ebb832c6a2625eba | https://github.com/choria-io/go-choria/blob/2c773ed36498f426852fd294ebb832c6a2625eba/aagent/machine/machine.go#L138-L168 |
15,924 | choria-io/go-choria | aagent/machine/machine.go | SetIdentity | func (m *Machine) SetIdentity(id string) {
m.Lock()
defer m.Unlock()
m.identity = id
} | go | func (m *Machine) SetIdentity(id string) {
m.Lock()
defer m.Unlock()
m.identity = id
} | [
"func",
"(",
"m",
"*",
"Machine",
")",
"SetIdentity",
"(",
"id",
"string",
")",
"{",
"m",
".",
"Lock",
"(",
")",
"\n",
"defer",
"m",
".",
"Unlock",
"(",
")",
"\n\n",
"m",
".",
"identity",
"=",
"id",
"\n",
"}"
] | // SetIdentity sets the identity of the node hosting this machine | [
"SetIdentity",
"sets",
"the",
"identity",
"of",
"the",
"node",
"hosting",
"this",
"machine"
] | 2c773ed36498f426852fd294ebb832c6a2625eba | https://github.com/choria-io/go-choria/blob/2c773ed36498f426852fd294ebb832c6a2625eba/aagent/machine/machine.go#L171-L176 |
15,925 | choria-io/go-choria | aagent/machine/machine.go | Validate | func (m *Machine) Validate() error {
if m.MachineName == "" {
return fmt.Errorf("a machine name is required")
}
if m.MachineVersion == "" {
return fmt.Errorf("a machine version is required")
}
if m.InitialState == "" {
return fmt.Errorf("an initial state is required")
}
if len(m.Transitions) == 0 {
return fmt.Errorf("no transitions defined")
}
if len(m.WatcherDefs) == 0 {
return fmt.Errorf("no watchers defined")
}
for _, w := range m.Watchers() {
err := w.ParseAnnounceInterval()
if err != nil {
return err
}
}
return nil
} | go | func (m *Machine) Validate() error {
if m.MachineName == "" {
return fmt.Errorf("a machine name is required")
}
if m.MachineVersion == "" {
return fmt.Errorf("a machine version is required")
}
if m.InitialState == "" {
return fmt.Errorf("an initial state is required")
}
if len(m.Transitions) == 0 {
return fmt.Errorf("no transitions defined")
}
if len(m.WatcherDefs) == 0 {
return fmt.Errorf("no watchers defined")
}
for _, w := range m.Watchers() {
err := w.ParseAnnounceInterval()
if err != nil {
return err
}
}
return nil
} | [
"func",
"(",
"m",
"*",
"Machine",
")",
"Validate",
"(",
")",
"error",
"{",
"if",
"m",
".",
"MachineName",
"==",
"\"",
"\"",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"m",
".",
"MachineVersion",
"==",
"\""... | // Validate performs basic validation on the machine settings | [
"Validate",
"performs",
"basic",
"validation",
"on",
"the",
"machine",
"settings"
] | 2c773ed36498f426852fd294ebb832c6a2625eba | https://github.com/choria-io/go-choria/blob/2c773ed36498f426852fd294ebb832c6a2625eba/aagent/machine/machine.go#L233-L262 |
15,926 | choria-io/go-choria | aagent/machine/machine.go | Setup | func (m *Machine) Setup() error {
err := m.Validate()
if err != nil {
return errors.Wrapf(err, "validation failed")
}
return m.buildFSM()
} | go | func (m *Machine) Setup() error {
err := m.Validate()
if err != nil {
return errors.Wrapf(err, "validation failed")
}
return m.buildFSM()
} | [
"func",
"(",
"m",
"*",
"Machine",
")",
"Setup",
"(",
")",
"error",
"{",
"err",
":=",
"m",
".",
"Validate",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"... | // Setup validates and prepares the machine for execution | [
"Setup",
"validates",
"and",
"prepares",
"the",
"machine",
"for",
"execution"
] | 2c773ed36498f426852fd294ebb832c6a2625eba | https://github.com/choria-io/go-choria/blob/2c773ed36498f426852fd294ebb832c6a2625eba/aagent/machine/machine.go#L265-L272 |
15,927 | choria-io/go-choria | aagent/machine/machine.go | Start | func (m *Machine) Start(ctx context.Context, wg *sync.WaitGroup) (started chan struct{}) {
m.ctx, m.cancel = context.WithCancel(ctx)
started = make(chan struct{})
runf := func() {
if m.SplayStart > 0 {
s1 := rand.NewSource(time.Now().UnixNano())
r1 := rand.New(s1)
sleepSeconds := time.Duration(r1.Intn(m.SplayStart)) * time.Second
m.Infof(m.MachineName, "Sleeping %v before starting Autonomous Agent", sleepSeconds)
t := time.NewTimer(sleepSeconds)
select {
case <-t.C:
case <-m.ctx.Done():
m.Infof(m.MachineName, "Exiting on context interrupt")
return
}
}
m.Infof(m.MachineName, "Starting Choria Machine %s version %s from %s", m.MachineName, m.MachineVersion, m.directory)
m.startTime = time.Now().UTC()
err := m.manager.Run(m.ctx, wg)
if err != nil {
m.Errorf(m.MachineName, "Could not start manager: %s", err)
}
started <- struct{}{}
}
go runf()
return started
} | go | func (m *Machine) Start(ctx context.Context, wg *sync.WaitGroup) (started chan struct{}) {
m.ctx, m.cancel = context.WithCancel(ctx)
started = make(chan struct{})
runf := func() {
if m.SplayStart > 0 {
s1 := rand.NewSource(time.Now().UnixNano())
r1 := rand.New(s1)
sleepSeconds := time.Duration(r1.Intn(m.SplayStart)) * time.Second
m.Infof(m.MachineName, "Sleeping %v before starting Autonomous Agent", sleepSeconds)
t := time.NewTimer(sleepSeconds)
select {
case <-t.C:
case <-m.ctx.Done():
m.Infof(m.MachineName, "Exiting on context interrupt")
return
}
}
m.Infof(m.MachineName, "Starting Choria Machine %s version %s from %s", m.MachineName, m.MachineVersion, m.directory)
m.startTime = time.Now().UTC()
err := m.manager.Run(m.ctx, wg)
if err != nil {
m.Errorf(m.MachineName, "Could not start manager: %s", err)
}
started <- struct{}{}
}
go runf()
return started
} | [
"func",
"(",
"m",
"*",
"Machine",
")",
"Start",
"(",
"ctx",
"context",
".",
"Context",
",",
"wg",
"*",
"sync",
".",
"WaitGroup",
")",
"(",
"started",
"chan",
"struct",
"{",
"}",
")",
"{",
"m",
".",
"ctx",
",",
"m",
".",
"cancel",
"=",
"context",
... | // Start runs the machine in the background | [
"Start",
"runs",
"the",
"machine",
"in",
"the",
"background"
] | 2c773ed36498f426852fd294ebb832c6a2625eba | https://github.com/choria-io/go-choria/blob/2c773ed36498f426852fd294ebb832c6a2625eba/aagent/machine/machine.go#L275-L312 |
15,928 | choria-io/go-choria | aagent/machine/machine.go | Stop | func (m *Machine) Stop() {
if m.cancel != nil {
m.Infof("runner", "Stopping")
m.cancel()
}
} | go | func (m *Machine) Stop() {
if m.cancel != nil {
m.Infof("runner", "Stopping")
m.cancel()
}
} | [
"func",
"(",
"m",
"*",
"Machine",
")",
"Stop",
"(",
")",
"{",
"if",
"m",
".",
"cancel",
"!=",
"nil",
"{",
"m",
".",
"Infof",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"m",
".",
"cancel",
"(",
")",
"\n",
"}",
"\n",
"}"
] | // Stop stops a running machine by canceling its context | [
"Stop",
"stops",
"a",
"running",
"machine",
"by",
"canceling",
"its",
"context"
] | 2c773ed36498f426852fd294ebb832c6a2625eba | https://github.com/choria-io/go-choria/blob/2c773ed36498f426852fd294ebb832c6a2625eba/aagent/machine/machine.go#L315-L320 |
15,929 | choria-io/go-choria | aagent/machine/machine.go | Transition | func (m *Machine) Transition(t string, args ...interface{}) error {
m.Lock()
defer m.Unlock()
if t == "" {
return nil
}
if m.fsm.Can(t) {
m.fsm.Event(t, args...)
} else {
m.Warnf("machine", "Could not fire '%s' event while in %s", t, m.fsm.Current())
}
return nil
} | go | func (m *Machine) Transition(t string, args ...interface{}) error {
m.Lock()
defer m.Unlock()
if t == "" {
return nil
}
if m.fsm.Can(t) {
m.fsm.Event(t, args...)
} else {
m.Warnf("machine", "Could not fire '%s' event while in %s", t, m.fsm.Current())
}
return nil
} | [
"func",
"(",
"m",
"*",
"Machine",
")",
"Transition",
"(",
"t",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"error",
"{",
"m",
".",
"Lock",
"(",
")",
"\n",
"defer",
"m",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"t",
"==",
"\"",
"\"",... | // Transition performs the machine transition as defined by event t | [
"Transition",
"performs",
"the",
"machine",
"transition",
"as",
"defined",
"by",
"event",
"t"
] | 2c773ed36498f426852fd294ebb832c6a2625eba | https://github.com/choria-io/go-choria/blob/2c773ed36498f426852fd294ebb832c6a2625eba/aagent/machine/machine.go#L323-L338 |
15,930 | choria-io/go-choria | aagent/machine/machine.go | Can | func (m *Machine) Can(t string) bool {
return m.fsm.Can(t)
} | go | func (m *Machine) Can(t string) bool {
return m.fsm.Can(t)
} | [
"func",
"(",
"m",
"*",
"Machine",
")",
"Can",
"(",
"t",
"string",
")",
"bool",
"{",
"return",
"m",
".",
"fsm",
".",
"Can",
"(",
"t",
")",
"\n",
"}"
] | // Can determines if a transition could be performed | [
"Can",
"determines",
"if",
"a",
"transition",
"could",
"be",
"performed"
] | 2c773ed36498f426852fd294ebb832c6a2625eba | https://github.com/choria-io/go-choria/blob/2c773ed36498f426852fd294ebb832c6a2625eba/aagent/machine/machine.go#L341-L343 |
15,931 | choria-io/go-choria | aagent/info.go | AllMachineStates | func (a *AAgent) AllMachineStates() (states []MachineState, err error) {
states = []MachineState{}
a.Lock()
defer a.Unlock()
for _, m := range a.machines {
state := MachineState{
Name: m.machine.Name(),
Version: m.machine.Version(),
Path: m.machine.Directory(),
ID: m.machine.InstanceID(),
State: m.machine.State(),
StartTimeUTC: m.machine.StartTime().Unix(),
AvailableTransitions: m.machine.AvailableTransitions(),
}
states = append(states, state)
}
return states, nil
} | go | func (a *AAgent) AllMachineStates() (states []MachineState, err error) {
states = []MachineState{}
a.Lock()
defer a.Unlock()
for _, m := range a.machines {
state := MachineState{
Name: m.machine.Name(),
Version: m.machine.Version(),
Path: m.machine.Directory(),
ID: m.machine.InstanceID(),
State: m.machine.State(),
StartTimeUTC: m.machine.StartTime().Unix(),
AvailableTransitions: m.machine.AvailableTransitions(),
}
states = append(states, state)
}
return states, nil
} | [
"func",
"(",
"a",
"*",
"AAgent",
")",
"AllMachineStates",
"(",
")",
"(",
"states",
"[",
"]",
"MachineState",
",",
"err",
"error",
")",
"{",
"states",
"=",
"[",
"]",
"MachineState",
"{",
"}",
"\n\n",
"a",
".",
"Lock",
"(",
")",
"\n",
"defer",
"a",
... | // AllMachineStates retrieves a list of machines and their states | [
"AllMachineStates",
"retrieves",
"a",
"list",
"of",
"machines",
"and",
"their",
"states"
] | 2c773ed36498f426852fd294ebb832c6a2625eba | https://github.com/choria-io/go-choria/blob/2c773ed36498f426852fd294ebb832c6a2625eba/aagent/info.go#L15-L36 |
15,932 | choria-io/go-choria | choria/util.go | StrToBool | func StrToBool(s string) (bool, error) {
clean := strings.TrimSpace(s)
if regexp.MustCompile(`(?i)^(1|yes|true|y|t)$`).MatchString(clean) {
return true, nil
}
if regexp.MustCompile(`(?i)^(0|no|false|n|f)$`).MatchString(clean) {
return false, nil
}
return false, fmt.Errorf("cannot convert string value '%s' into a boolean", clean)
} | go | func StrToBool(s string) (bool, error) {
clean := strings.TrimSpace(s)
if regexp.MustCompile(`(?i)^(1|yes|true|y|t)$`).MatchString(clean) {
return true, nil
}
if regexp.MustCompile(`(?i)^(0|no|false|n|f)$`).MatchString(clean) {
return false, nil
}
return false, fmt.Errorf("cannot convert string value '%s' into a boolean", clean)
} | [
"func",
"StrToBool",
"(",
"s",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"clean",
":=",
"strings",
".",
"TrimSpace",
"(",
"s",
")",
"\n\n",
"if",
"regexp",
".",
"MustCompile",
"(",
"`(?i)^(1|yes|true|y|t)$`",
")",
".",
"MatchString",
"(",
"clea... | // StrToBool converts a typical mcollective boolianish string to bool | [
"StrToBool",
"converts",
"a",
"typical",
"mcollective",
"boolianish",
"string",
"to",
"bool"
] | 2c773ed36498f426852fd294ebb832c6a2625eba | https://github.com/choria-io/go-choria/blob/2c773ed36498f426852fd294ebb832c6a2625eba/choria/util.go#L57-L69 |
15,933 | choria-io/go-choria | choria/util.go | SliceGroups | func SliceGroups(input []string, size int, fn func(group []string)) {
// how many to add
padding := size - (len(input) % size)
if padding != size {
p := []string{}
for i := 0; i <= padding; i++ {
p = append(p, "")
}
input = append(input, p...)
}
// how many chunks we're making
count := len(input) / size
for i := 0; i < count; i++ {
chunk := input[i*size : i*size+size]
fn(chunk)
}
} | go | func SliceGroups(input []string, size int, fn func(group []string)) {
// how many to add
padding := size - (len(input) % size)
if padding != size {
p := []string{}
for i := 0; i <= padding; i++ {
p = append(p, "")
}
input = append(input, p...)
}
// how many chunks we're making
count := len(input) / size
for i := 0; i < count; i++ {
chunk := input[i*size : i*size+size]
fn(chunk)
}
} | [
"func",
"SliceGroups",
"(",
"input",
"[",
"]",
"string",
",",
"size",
"int",
",",
"fn",
"func",
"(",
"group",
"[",
"]",
"string",
")",
")",
"{",
"// how many to add",
"padding",
":=",
"size",
"-",
"(",
"len",
"(",
"input",
")",
"%",
"size",
")",
"\... | // SliceGroups takes a slice of words and make new chunks of given size
// and call the function with the sub slice. If there are not enough
// items in the input slice empty strings will pad the last group | [
"SliceGroups",
"takes",
"a",
"slice",
"of",
"words",
"and",
"make",
"new",
"chunks",
"of",
"given",
"size",
"and",
"call",
"the",
"function",
"with",
"the",
"sub",
"slice",
".",
"If",
"there",
"are",
"not",
"enough",
"items",
"in",
"the",
"input",
"slice... | 2c773ed36498f426852fd294ebb832c6a2625eba | https://github.com/choria-io/go-choria/blob/2c773ed36498f426852fd294ebb832c6a2625eba/choria/util.go#L74-L95 |
15,934 | choria-io/go-choria | choria/util.go | HomeDir | func HomeDir() (string, error) {
if runtime.GOOS == "windows" {
drive := os.Getenv("HOMEDRIVE")
home := os.Getenv("HOMEDIR")
if home == "" || drive == "" {
return "", fmt.Errorf("Cannot determine home dir, ensure HOMEDRIVE and HOMEDIR is set")
}
return filepath.Join(os.Getenv("HOMEDRIVE"), os.Getenv("HOMEDIR")), nil
}
home := os.Getenv("HOME")
if home == "" {
return "", fmt.Errorf("Cannot determine home dir, ensure HOME is set")
}
return home, nil
} | go | func HomeDir() (string, error) {
if runtime.GOOS == "windows" {
drive := os.Getenv("HOMEDRIVE")
home := os.Getenv("HOMEDIR")
if home == "" || drive == "" {
return "", fmt.Errorf("Cannot determine home dir, ensure HOMEDRIVE and HOMEDIR is set")
}
return filepath.Join(os.Getenv("HOMEDRIVE"), os.Getenv("HOMEDIR")), nil
}
home := os.Getenv("HOME")
if home == "" {
return "", fmt.Errorf("Cannot determine home dir, ensure HOME is set")
}
return home, nil
} | [
"func",
"HomeDir",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"if",
"runtime",
".",
"GOOS",
"==",
"\"",
"\"",
"{",
"drive",
":=",
"os",
".",
"Getenv",
"(",
"\"",
"\"",
")",
"\n",
"home",
":=",
"os",
".",
"Getenv",
"(",
"\"",
"\"",
")",
... | // HomeDir determines the home location without using the user package or requiring cgo
//
// On Unix it needs HOME set and on windows HOMEDRIVE and HOMEDIR | [
"HomeDir",
"determines",
"the",
"home",
"location",
"without",
"using",
"the",
"user",
"package",
"or",
"requiring",
"cgo",
"On",
"Unix",
"it",
"needs",
"HOME",
"set",
"and",
"on",
"windows",
"HOMEDRIVE",
"and",
"HOMEDIR"
] | 2c773ed36498f426852fd294ebb832c6a2625eba | https://github.com/choria-io/go-choria/blob/2c773ed36498f426852fd294ebb832c6a2625eba/choria/util.go#L100-L120 |
15,935 | choria-io/go-choria | choria/util.go | MatchAnyRegex | func MatchAnyRegex(str []byte, regex []string) bool {
for _, reg := range regex {
if matched, _ := regexp.Match(reg, str); matched {
return true
}
}
return false
} | go | func MatchAnyRegex(str []byte, regex []string) bool {
for _, reg := range regex {
if matched, _ := regexp.Match(reg, str); matched {
return true
}
}
return false
} | [
"func",
"MatchAnyRegex",
"(",
"str",
"[",
"]",
"byte",
",",
"regex",
"[",
"]",
"string",
")",
"bool",
"{",
"for",
"_",
",",
"reg",
":=",
"range",
"regex",
"{",
"if",
"matched",
",",
"_",
":=",
"regexp",
".",
"Match",
"(",
"reg",
",",
"str",
")",
... | // MatchAnyRegex checks str against a list of possible regex, if any match true is returned | [
"MatchAnyRegex",
"checks",
"str",
"against",
"a",
"list",
"of",
"possible",
"regex",
"if",
"any",
"match",
"true",
"is",
"returned"
] | 2c773ed36498f426852fd294ebb832c6a2625eba | https://github.com/choria-io/go-choria/blob/2c773ed36498f426852fd294ebb832c6a2625eba/choria/util.go#L163-L171 |
15,936 | choria-io/go-choria | choria/util.go | NewRequestID | func NewRequestID() (string, error) {
id, err := uuid.NewV4()
if err != nil {
return "", err
}
return strings.Replace(id.String(), "-", "", -1), nil
} | go | func NewRequestID() (string, error) {
id, err := uuid.NewV4()
if err != nil {
return "", err
}
return strings.Replace(id.String(), "-", "", -1), nil
} | [
"func",
"NewRequestID",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"id",
",",
"err",
":=",
"uuid",
".",
"NewV4",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"strings",
".",
... | // NewRequestID Creates a new RequestID | [
"NewRequestID",
"Creates",
"a",
"new",
"RequestID"
] | 2c773ed36498f426852fd294ebb832c6a2625eba | https://github.com/choria-io/go-choria/blob/2c773ed36498f426852fd294ebb832c6a2625eba/choria/util.go#L174-L181 |
15,937 | mdlayher/dhcp6 | dhcp6opts/iaprefix.go | NewIAPrefix | func NewIAPrefix(preferred time.Duration, valid time.Duration, prefixLength uint8, prefix net.IP, options dhcp6.Options) (*IAPrefix, error) {
// Preferred lifetime must always be less than valid lifetime.
if preferred > valid {
return nil, ErrInvalidLifetimes
}
// From documentation: If ip is not an IPv4 address, To4 returns nil.
if prefix.To4() != nil {
return nil, ErrInvalidIP
}
// If no options set, make empty map
if options == nil {
options = make(dhcp6.Options)
}
return &IAPrefix{
PreferredLifetime: preferred,
ValidLifetime: valid,
PrefixLength: prefixLength,
Prefix: prefix,
Options: options,
}, nil
} | go | func NewIAPrefix(preferred time.Duration, valid time.Duration, prefixLength uint8, prefix net.IP, options dhcp6.Options) (*IAPrefix, error) {
// Preferred lifetime must always be less than valid lifetime.
if preferred > valid {
return nil, ErrInvalidLifetimes
}
// From documentation: If ip is not an IPv4 address, To4 returns nil.
if prefix.To4() != nil {
return nil, ErrInvalidIP
}
// If no options set, make empty map
if options == nil {
options = make(dhcp6.Options)
}
return &IAPrefix{
PreferredLifetime: preferred,
ValidLifetime: valid,
PrefixLength: prefixLength,
Prefix: prefix,
Options: options,
}, nil
} | [
"func",
"NewIAPrefix",
"(",
"preferred",
"time",
".",
"Duration",
",",
"valid",
"time",
".",
"Duration",
",",
"prefixLength",
"uint8",
",",
"prefix",
"net",
".",
"IP",
",",
"options",
"dhcp6",
".",
"Options",
")",
"(",
"*",
"IAPrefix",
",",
"error",
")",... | // NewIAPrefix creates a new IAPrefix from preferred and valid lifetime
// durations, an IPv6 prefix length, an IPv6 prefix, and an optional Options
// map.
//
// The preferred lifetime duration must be less than the valid lifetime
// duration. The IPv6 prefix must be exactly 16 bytes, the correct length
// for an IPv6 address. Failure to meet either of these conditions will result
// in an error. If an Options map is not specified, a new one will be
// allocated. | [
"NewIAPrefix",
"creates",
"a",
"new",
"IAPrefix",
"from",
"preferred",
"and",
"valid",
"lifetime",
"durations",
"an",
"IPv6",
"prefix",
"length",
"an",
"IPv6",
"prefix",
"and",
"an",
"optional",
"Options",
"map",
".",
"The",
"preferred",
"lifetime",
"duration",
... | 2a67805d7d0b0bad6c1103058981afdea583b459 | https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/iaprefix.go#L61-L84 |
15,938 | mdlayher/dhcp6 | dhcp6opts/iaprefix.go | MarshalBinary | func (i *IAPrefix) MarshalBinary() ([]byte, error) {
// 4 bytes: preferred lifetime
// 4 bytes: valid lifetime
// 1 byte : prefix length
// 16 bytes: IPv6 prefix
// N bytes: options
b := buffer.New(nil)
b.Write32(uint32(i.PreferredLifetime / time.Second))
b.Write32(uint32(i.ValidLifetime / time.Second))
b.Write8(i.PrefixLength)
copy(b.WriteN(net.IPv6len), i.Prefix)
opts, err := i.Options.MarshalBinary()
if err != nil {
return nil, err
}
b.WriteBytes(opts)
return b.Data(), nil
} | go | func (i *IAPrefix) MarshalBinary() ([]byte, error) {
// 4 bytes: preferred lifetime
// 4 bytes: valid lifetime
// 1 byte : prefix length
// 16 bytes: IPv6 prefix
// N bytes: options
b := buffer.New(nil)
b.Write32(uint32(i.PreferredLifetime / time.Second))
b.Write32(uint32(i.ValidLifetime / time.Second))
b.Write8(i.PrefixLength)
copy(b.WriteN(net.IPv6len), i.Prefix)
opts, err := i.Options.MarshalBinary()
if err != nil {
return nil, err
}
b.WriteBytes(opts)
return b.Data(), nil
} | [
"func",
"(",
"i",
"*",
"IAPrefix",
")",
"MarshalBinary",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"// 4 bytes: preferred lifetime",
"// 4 bytes: valid lifetime",
"// 1 byte : prefix length",
"// 16 bytes: IPv6 prefix",
"// N bytes: options",
"b",
":=... | // MarshalBinary allocates a byte slice containing the data from a IAPrefix. | [
"MarshalBinary",
"allocates",
"a",
"byte",
"slice",
"containing",
"the",
"data",
"from",
"a",
"IAPrefix",
"."
] | 2a67805d7d0b0bad6c1103058981afdea583b459 | https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/iaprefix.go#L87-L106 |
15,939 | mdlayher/dhcp6 | cmd/dhcp6d/main.go | ServeDHCP | func (h *Handler) ServeDHCP(w dhcp6server.ResponseSender, r *dhcp6server.Request) {
if err := h.handler(h.ip, w, r); err != nil {
log.Println(err)
}
} | go | func (h *Handler) ServeDHCP(w dhcp6server.ResponseSender, r *dhcp6server.Request) {
if err := h.handler(h.ip, w, r); err != nil {
log.Println(err)
}
} | [
"func",
"(",
"h",
"*",
"Handler",
")",
"ServeDHCP",
"(",
"w",
"dhcp6server",
".",
"ResponseSender",
",",
"r",
"*",
"dhcp6server",
".",
"Request",
")",
"{",
"if",
"err",
":=",
"h",
".",
"handler",
"(",
"h",
".",
"ip",
",",
"w",
",",
"r",
")",
";",... | // ServeDHCP is a dhcp6.Handler which invokes an internal handler that
// allows errors to be returned and handled in one place. | [
"ServeDHCP",
"is",
"a",
"dhcp6",
".",
"Handler",
"which",
"invokes",
"an",
"internal",
"handler",
"that",
"allows",
"errors",
"to",
"be",
"returned",
"and",
"handled",
"in",
"one",
"place",
"."
] | 2a67805d7d0b0bad6c1103058981afdea583b459 | https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/cmd/dhcp6d/main.go#L50-L54 |
15,940 | mdlayher/dhcp6 | cmd/dhcp6d/main.go | handle | func handle(ip net.IP, w dhcp6server.ResponseSender, r *dhcp6server.Request) error {
// Accept only Solicit, Request, or Confirm, since this server
// does not handle Information Request or other message types
valid := map[dhcp6.MessageType]struct{}{
dhcp6.MessageTypeSolicit: {},
dhcp6.MessageTypeRequest: {},
dhcp6.MessageTypeConfirm: {},
}
if _, ok := valid[r.MessageType]; !ok {
return nil
}
// Make sure client sent a client ID.
duid, err := r.Options.GetOne(dhcp6.OptionClientID)
if err != nil {
return nil
}
// Log information about the incoming request.
log.Printf("[%s] id: %s, type: %d, len: %d, tx: %s",
hex.EncodeToString(duid),
r.RemoteAddr,
r.MessageType,
r.Length,
hex.EncodeToString(r.TransactionID[:]),
)
// Print out options the client has requested
if opts, err := dhcp6opts.GetOptionRequest(r.Options); err == nil {
log.Println("\t- requested:")
for _, o := range opts {
log.Printf("\t\t - %s", o)
}
}
// Client must send a IANA to retrieve an IPv6 address
ianas, err := dhcp6opts.GetIANA(r.Options)
if err == dhcp6.ErrOptionNotPresent {
log.Println("no IANAs provided")
return nil
}
if err != nil {
return err
}
// Only accept one IANA
if len(ianas) > 1 {
log.Println("can only handle one IANA")
return nil
}
ia := ianas[0]
log.Printf("\tIANA: %s (%s, %s), opts: %v",
hex.EncodeToString(ia.IAID[:]),
ia.T1,
ia.T2,
ia.Options,
)
// Instruct client to prefer this server unconditionally
_ = w.Options().Add(dhcp6.OptionPreference, dhcp6opts.Preference(255))
// IANA may already have an IAAddr if an address was already assigned.
// If not, assign a new one.
iaaddrs, err := dhcp6opts.GetIAAddr(ia.Options)
switch err {
case dhcp6.ErrOptionNotPresent:
// Client did not indicate a previous address, and is soliciting.
// Advertise a new IPv6 address.
if r.MessageType == dhcp6.MessageTypeSolicit {
return newIAAddr(ia, ip, w, r)
}
// Client did not indicate an address and is not soliciting. Ignore.
return nil
case nil:
// Fall through below.
default:
return err
}
// Confirm or renew an existing IPv6 address
// Must have an IAAddr, but we ignore if more than one is present
if len(iaaddrs) == 0 {
return nil
}
iaa := iaaddrs[0]
log.Printf("\t\tIAAddr: %s (%s, %s), opts: %v",
iaa.IP,
iaa.PreferredLifetime,
iaa.ValidLifetime,
iaa.Options,
)
// Add IAAddr inside IANA, add IANA to options
_ = ia.Options.Add(dhcp6.OptionIAAddr, iaa)
_ = w.Options().Add(dhcp6.OptionIANA, ia)
// Send reply to client
_, err = w.Send(dhcp6.MessageTypeReply)
return err
} | go | func handle(ip net.IP, w dhcp6server.ResponseSender, r *dhcp6server.Request) error {
// Accept only Solicit, Request, or Confirm, since this server
// does not handle Information Request or other message types
valid := map[dhcp6.MessageType]struct{}{
dhcp6.MessageTypeSolicit: {},
dhcp6.MessageTypeRequest: {},
dhcp6.MessageTypeConfirm: {},
}
if _, ok := valid[r.MessageType]; !ok {
return nil
}
// Make sure client sent a client ID.
duid, err := r.Options.GetOne(dhcp6.OptionClientID)
if err != nil {
return nil
}
// Log information about the incoming request.
log.Printf("[%s] id: %s, type: %d, len: %d, tx: %s",
hex.EncodeToString(duid),
r.RemoteAddr,
r.MessageType,
r.Length,
hex.EncodeToString(r.TransactionID[:]),
)
// Print out options the client has requested
if opts, err := dhcp6opts.GetOptionRequest(r.Options); err == nil {
log.Println("\t- requested:")
for _, o := range opts {
log.Printf("\t\t - %s", o)
}
}
// Client must send a IANA to retrieve an IPv6 address
ianas, err := dhcp6opts.GetIANA(r.Options)
if err == dhcp6.ErrOptionNotPresent {
log.Println("no IANAs provided")
return nil
}
if err != nil {
return err
}
// Only accept one IANA
if len(ianas) > 1 {
log.Println("can only handle one IANA")
return nil
}
ia := ianas[0]
log.Printf("\tIANA: %s (%s, %s), opts: %v",
hex.EncodeToString(ia.IAID[:]),
ia.T1,
ia.T2,
ia.Options,
)
// Instruct client to prefer this server unconditionally
_ = w.Options().Add(dhcp6.OptionPreference, dhcp6opts.Preference(255))
// IANA may already have an IAAddr if an address was already assigned.
// If not, assign a new one.
iaaddrs, err := dhcp6opts.GetIAAddr(ia.Options)
switch err {
case dhcp6.ErrOptionNotPresent:
// Client did not indicate a previous address, and is soliciting.
// Advertise a new IPv6 address.
if r.MessageType == dhcp6.MessageTypeSolicit {
return newIAAddr(ia, ip, w, r)
}
// Client did not indicate an address and is not soliciting. Ignore.
return nil
case nil:
// Fall through below.
default:
return err
}
// Confirm or renew an existing IPv6 address
// Must have an IAAddr, but we ignore if more than one is present
if len(iaaddrs) == 0 {
return nil
}
iaa := iaaddrs[0]
log.Printf("\t\tIAAddr: %s (%s, %s), opts: %v",
iaa.IP,
iaa.PreferredLifetime,
iaa.ValidLifetime,
iaa.Options,
)
// Add IAAddr inside IANA, add IANA to options
_ = ia.Options.Add(dhcp6.OptionIAAddr, iaa)
_ = w.Options().Add(dhcp6.OptionIANA, ia)
// Send reply to client
_, err = w.Send(dhcp6.MessageTypeReply)
return err
} | [
"func",
"handle",
"(",
"ip",
"net",
".",
"IP",
",",
"w",
"dhcp6server",
".",
"ResponseSender",
",",
"r",
"*",
"dhcp6server",
".",
"Request",
")",
"error",
"{",
"// Accept only Solicit, Request, or Confirm, since this server",
"// does not handle Information Request or oth... | // handle is a handler which assigns IPv6 addresses using DHCPv6. | [
"handle",
"is",
"a",
"handler",
"which",
"assigns",
"IPv6",
"addresses",
"using",
"DHCPv6",
"."
] | 2a67805d7d0b0bad6c1103058981afdea583b459 | https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/cmd/dhcp6d/main.go#L61-L165 |
15,941 | mdlayher/dhcp6 | cmd/dhcp6d/main.go | newIAAddr | func newIAAddr(ia *dhcp6opts.IANA, ip net.IP, w dhcp6server.ResponseSender, r *dhcp6server.Request) error {
// Send IPv6 address with 60 second preferred lifetime,
// 90 second valid lifetime, no extra options
iaaddr, err := dhcp6opts.NewIAAddr(ip, 60*time.Second, 90*time.Second, nil)
if err != nil {
return err
}
// Add IAAddr inside IANA, add IANA to options
_ = ia.Options.Add(dhcp6.OptionIAAddr, iaaddr)
_ = w.Options().Add(dhcp6.OptionIANA, ia)
// Advertise address to soliciting clients
log.Printf("advertising IP: %s", ip)
_, err = w.Send(dhcp6.MessageTypeAdvertise)
return err
} | go | func newIAAddr(ia *dhcp6opts.IANA, ip net.IP, w dhcp6server.ResponseSender, r *dhcp6server.Request) error {
// Send IPv6 address with 60 second preferred lifetime,
// 90 second valid lifetime, no extra options
iaaddr, err := dhcp6opts.NewIAAddr(ip, 60*time.Second, 90*time.Second, nil)
if err != nil {
return err
}
// Add IAAddr inside IANA, add IANA to options
_ = ia.Options.Add(dhcp6.OptionIAAddr, iaaddr)
_ = w.Options().Add(dhcp6.OptionIANA, ia)
// Advertise address to soliciting clients
log.Printf("advertising IP: %s", ip)
_, err = w.Send(dhcp6.MessageTypeAdvertise)
return err
} | [
"func",
"newIAAddr",
"(",
"ia",
"*",
"dhcp6opts",
".",
"IANA",
",",
"ip",
"net",
".",
"IP",
",",
"w",
"dhcp6server",
".",
"ResponseSender",
",",
"r",
"*",
"dhcp6server",
".",
"Request",
")",
"error",
"{",
"// Send IPv6 address with 60 second preferred lifetime,"... | // newIAAddr creates a IAAddr for a IANA using the specified IPv6 address,
// and advertises it to a client. | [
"newIAAddr",
"creates",
"a",
"IAAddr",
"for",
"a",
"IANA",
"using",
"the",
"specified",
"IPv6",
"address",
"and",
"advertises",
"it",
"to",
"a",
"client",
"."
] | 2a67805d7d0b0bad6c1103058981afdea583b459 | https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/cmd/dhcp6d/main.go#L169-L185 |
15,942 | mdlayher/dhcp6 | dhcp6opts/options.go | GetClientID | func GetClientID(o dhcp6.Options) (DUID, error) {
v, err := o.GetOne(dhcp6.OptionClientID)
if err != nil {
return nil, err
}
return parseDUID(v)
} | go | func GetClientID(o dhcp6.Options) (DUID, error) {
v, err := o.GetOne(dhcp6.OptionClientID)
if err != nil {
return nil, err
}
return parseDUID(v)
} | [
"func",
"GetClientID",
"(",
"o",
"dhcp6",
".",
"Options",
")",
"(",
"DUID",
",",
"error",
")",
"{",
"v",
",",
"err",
":=",
"o",
".",
"GetOne",
"(",
"dhcp6",
".",
"OptionClientID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"e... | // GetClientID returns the Client Identifier Option value, as described in RFC
// 3315, Section 22.2.
//
// The DUID returned allows unique identification of a client to a server. | [
"GetClientID",
"returns",
"the",
"Client",
"Identifier",
"Option",
"value",
"as",
"described",
"in",
"RFC",
"3315",
"Section",
"22",
".",
"2",
".",
"The",
"DUID",
"returned",
"allows",
"unique",
"identification",
"of",
"a",
"client",
"to",
"a",
"server",
"."... | 2a67805d7d0b0bad6c1103058981afdea583b459 | https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/options.go#L11-L18 |
15,943 | mdlayher/dhcp6 | dhcp6opts/options.go | GetServerID | func GetServerID(o dhcp6.Options) (DUID, error) {
v, err := o.GetOne(dhcp6.OptionServerID)
if err != nil {
return nil, err
}
return parseDUID(v)
} | go | func GetServerID(o dhcp6.Options) (DUID, error) {
v, err := o.GetOne(dhcp6.OptionServerID)
if err != nil {
return nil, err
}
return parseDUID(v)
} | [
"func",
"GetServerID",
"(",
"o",
"dhcp6",
".",
"Options",
")",
"(",
"DUID",
",",
"error",
")",
"{",
"v",
",",
"err",
":=",
"o",
".",
"GetOne",
"(",
"dhcp6",
".",
"OptionServerID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"e... | // GetServerID returns the Server Identifier Option value, as described in RFC
// 3315, Section 22.3.
//
// The DUID returned allows unique identification of a server to a client. | [
"GetServerID",
"returns",
"the",
"Server",
"Identifier",
"Option",
"value",
"as",
"described",
"in",
"RFC",
"3315",
"Section",
"22",
".",
"3",
".",
"The",
"DUID",
"returned",
"allows",
"unique",
"identification",
"of",
"a",
"server",
"to",
"a",
"client",
"."... | 2a67805d7d0b0bad6c1103058981afdea583b459 | https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/options.go#L24-L31 |
15,944 | mdlayher/dhcp6 | dhcp6opts/options.go | GetIANA | func GetIANA(o dhcp6.Options) ([]*IANA, error) {
vv, err := o.Get(dhcp6.OptionIANA)
if err != nil {
return nil, err
}
// Parse each IA_NA value
iana := make([]*IANA, len(vv))
for i := range vv {
iana[i] = &IANA{}
if err := iana[i].UnmarshalBinary(vv[i]); err != nil {
return nil, err
}
}
return iana, nil
} | go | func GetIANA(o dhcp6.Options) ([]*IANA, error) {
vv, err := o.Get(dhcp6.OptionIANA)
if err != nil {
return nil, err
}
// Parse each IA_NA value
iana := make([]*IANA, len(vv))
for i := range vv {
iana[i] = &IANA{}
if err := iana[i].UnmarshalBinary(vv[i]); err != nil {
return nil, err
}
}
return iana, nil
} | [
"func",
"GetIANA",
"(",
"o",
"dhcp6",
".",
"Options",
")",
"(",
"[",
"]",
"*",
"IANA",
",",
"error",
")",
"{",
"vv",
",",
"err",
":=",
"o",
".",
"Get",
"(",
"dhcp6",
".",
"OptionIANA",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
... | // GetIANA returns the Identity Association for Non-temporary Addresses Option
// value, as described in RFC 3315, Section 22.4.
//
// Multiple IANA values may be present in a single DHCP request. | [
"GetIANA",
"returns",
"the",
"Identity",
"Association",
"for",
"Non",
"-",
"temporary",
"Addresses",
"Option",
"value",
"as",
"described",
"in",
"RFC",
"3315",
"Section",
"22",
".",
"4",
".",
"Multiple",
"IANA",
"values",
"may",
"be",
"present",
"in",
"a",
... | 2a67805d7d0b0bad6c1103058981afdea583b459 | https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/options.go#L37-L52 |
15,945 | mdlayher/dhcp6 | dhcp6opts/options.go | GetIATA | func GetIATA(o dhcp6.Options) ([]*IATA, error) {
vv, err := o.Get(dhcp6.OptionIATA)
if err != nil {
return nil, err
}
// Parse each IA_NA value
iata := make([]*IATA, len(vv))
for i := range vv {
iata[i] = &IATA{}
if err := iata[i].UnmarshalBinary(vv[i]); err != nil {
return nil, err
}
}
return iata, nil
} | go | func GetIATA(o dhcp6.Options) ([]*IATA, error) {
vv, err := o.Get(dhcp6.OptionIATA)
if err != nil {
return nil, err
}
// Parse each IA_NA value
iata := make([]*IATA, len(vv))
for i := range vv {
iata[i] = &IATA{}
if err := iata[i].UnmarshalBinary(vv[i]); err != nil {
return nil, err
}
}
return iata, nil
} | [
"func",
"GetIATA",
"(",
"o",
"dhcp6",
".",
"Options",
")",
"(",
"[",
"]",
"*",
"IATA",
",",
"error",
")",
"{",
"vv",
",",
"err",
":=",
"o",
".",
"Get",
"(",
"dhcp6",
".",
"OptionIATA",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
... | // GetIATA returns the Identity Association for Temporary Addresses Option
// value, as described in RFC 3315, Section 22.5.
//
// Multiple IATA values may be present in a single DHCP request. | [
"GetIATA",
"returns",
"the",
"Identity",
"Association",
"for",
"Temporary",
"Addresses",
"Option",
"value",
"as",
"described",
"in",
"RFC",
"3315",
"Section",
"22",
".",
"5",
".",
"Multiple",
"IATA",
"values",
"may",
"be",
"present",
"in",
"a",
"single",
"DH... | 2a67805d7d0b0bad6c1103058981afdea583b459 | https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/options.go#L58-L73 |
15,946 | mdlayher/dhcp6 | dhcp6opts/options.go | GetIAAddr | func GetIAAddr(o dhcp6.Options) ([]*IAAddr, error) {
vv, err := o.Get(dhcp6.OptionIAAddr)
if err != nil {
return nil, err
}
iaAddr := make([]*IAAddr, len(vv))
for i := range vv {
iaAddr[i] = &IAAddr{}
if err := iaAddr[i].UnmarshalBinary(vv[i]); err != nil {
return nil, err
}
}
return iaAddr, nil
} | go | func GetIAAddr(o dhcp6.Options) ([]*IAAddr, error) {
vv, err := o.Get(dhcp6.OptionIAAddr)
if err != nil {
return nil, err
}
iaAddr := make([]*IAAddr, len(vv))
for i := range vv {
iaAddr[i] = &IAAddr{}
if err := iaAddr[i].UnmarshalBinary(vv[i]); err != nil {
return nil, err
}
}
return iaAddr, nil
} | [
"func",
"GetIAAddr",
"(",
"o",
"dhcp6",
".",
"Options",
")",
"(",
"[",
"]",
"*",
"IAAddr",
",",
"error",
")",
"{",
"vv",
",",
"err",
":=",
"o",
".",
"Get",
"(",
"dhcp6",
".",
"OptionIAAddr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"... | // GetIAAddr returns the Identity Association Address Option value, as described
// in RFC 3315, Section 22.6.
//
// The IAAddr option must always appear encapsulated in the Options map of a
// IANA or IATA option. Multiple IAAddr values may be present in a single DHCP
// request. | [
"GetIAAddr",
"returns",
"the",
"Identity",
"Association",
"Address",
"Option",
"value",
"as",
"described",
"in",
"RFC",
"3315",
"Section",
"22",
".",
"6",
".",
"The",
"IAAddr",
"option",
"must",
"always",
"appear",
"encapsulated",
"in",
"the",
"Options",
"map"... | 2a67805d7d0b0bad6c1103058981afdea583b459 | https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/options.go#L81-L95 |
15,947 | mdlayher/dhcp6 | dhcp6opts/options.go | GetOptionRequest | func GetOptionRequest(o dhcp6.Options) (OptionRequestOption, error) {
v, err := o.GetOne(dhcp6.OptionORO)
if err != nil {
return nil, err
}
var oro OptionRequestOption
err = oro.UnmarshalBinary(v)
return oro, err
} | go | func GetOptionRequest(o dhcp6.Options) (OptionRequestOption, error) {
v, err := o.GetOne(dhcp6.OptionORO)
if err != nil {
return nil, err
}
var oro OptionRequestOption
err = oro.UnmarshalBinary(v)
return oro, err
} | [
"func",
"GetOptionRequest",
"(",
"o",
"dhcp6",
".",
"Options",
")",
"(",
"OptionRequestOption",
",",
"error",
")",
"{",
"v",
",",
"err",
":=",
"o",
".",
"GetOne",
"(",
"dhcp6",
".",
"OptionORO",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"ni... | // GetOptionRequest returns the Option Request Option value, as described in
// RFC 3315, Section 22.7.
//
// The slice of OptionCode values indicates the options a DHCP client is
// interested in receiving from a server. | [
"GetOptionRequest",
"returns",
"the",
"Option",
"Request",
"Option",
"value",
"as",
"described",
"in",
"RFC",
"3315",
"Section",
"22",
".",
"7",
".",
"The",
"slice",
"of",
"OptionCode",
"values",
"indicates",
"the",
"options",
"a",
"DHCP",
"client",
"is",
"i... | 2a67805d7d0b0bad6c1103058981afdea583b459 | https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/options.go#L102-L111 |
15,948 | mdlayher/dhcp6 | dhcp6opts/options.go | GetPreference | func GetPreference(o dhcp6.Options) (Preference, error) {
v, err := o.GetOne(dhcp6.OptionPreference)
if err != nil {
return 0, err
}
var p Preference
err = (&p).UnmarshalBinary(v)
return p, err
} | go | func GetPreference(o dhcp6.Options) (Preference, error) {
v, err := o.GetOne(dhcp6.OptionPreference)
if err != nil {
return 0, err
}
var p Preference
err = (&p).UnmarshalBinary(v)
return p, err
} | [
"func",
"GetPreference",
"(",
"o",
"dhcp6",
".",
"Options",
")",
"(",
"Preference",
",",
"error",
")",
"{",
"v",
",",
"err",
":=",
"o",
".",
"GetOne",
"(",
"dhcp6",
".",
"OptionPreference",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
"... | // GetPreference returns the Preference Option value, as described in RFC 3315,
// Section 22.8.
//
// The integer preference value is sent by a server to a client to affect the
// selection of a server by the client. | [
"GetPreference",
"returns",
"the",
"Preference",
"Option",
"value",
"as",
"described",
"in",
"RFC",
"3315",
"Section",
"22",
".",
"8",
".",
"The",
"integer",
"preference",
"value",
"is",
"sent",
"by",
"a",
"server",
"to",
"a",
"client",
"to",
"affect",
"th... | 2a67805d7d0b0bad6c1103058981afdea583b459 | https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/options.go#L118-L127 |
15,949 | mdlayher/dhcp6 | dhcp6opts/options.go | GetElapsedTime | func GetElapsedTime(o dhcp6.Options) (ElapsedTime, error) {
v, err := o.GetOne(dhcp6.OptionElapsedTime)
if err != nil {
return 0, err
}
var t ElapsedTime
err = (&t).UnmarshalBinary(v)
return t, err
} | go | func GetElapsedTime(o dhcp6.Options) (ElapsedTime, error) {
v, err := o.GetOne(dhcp6.OptionElapsedTime)
if err != nil {
return 0, err
}
var t ElapsedTime
err = (&t).UnmarshalBinary(v)
return t, err
} | [
"func",
"GetElapsedTime",
"(",
"o",
"dhcp6",
".",
"Options",
")",
"(",
"ElapsedTime",
",",
"error",
")",
"{",
"v",
",",
"err",
":=",
"o",
".",
"GetOne",
"(",
"dhcp6",
".",
"OptionElapsedTime",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
... | // GetElapsedTime returns the Elapsed Time Option value, as described in RFC
// 3315, Section 22.9.
//
// The time.Duration returned reports the time elapsed during a DHCP
// transaction, as reported by a client. | [
"GetElapsedTime",
"returns",
"the",
"Elapsed",
"Time",
"Option",
"value",
"as",
"described",
"in",
"RFC",
"3315",
"Section",
"22",
".",
"9",
".",
"The",
"time",
".",
"Duration",
"returned",
"reports",
"the",
"time",
"elapsed",
"during",
"a",
"DHCP",
"transac... | 2a67805d7d0b0bad6c1103058981afdea583b459 | https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/options.go#L134-L143 |
15,950 | mdlayher/dhcp6 | dhcp6opts/options.go | GetRelayMessageOption | func GetRelayMessageOption(o dhcp6.Options) (RelayMessageOption, error) {
v, err := o.GetOne(dhcp6.OptionRelayMsg)
if err != nil {
return nil, err
}
var r RelayMessageOption
err = (&r).UnmarshalBinary(v)
return r, err
} | go | func GetRelayMessageOption(o dhcp6.Options) (RelayMessageOption, error) {
v, err := o.GetOne(dhcp6.OptionRelayMsg)
if err != nil {
return nil, err
}
var r RelayMessageOption
err = (&r).UnmarshalBinary(v)
return r, err
} | [
"func",
"GetRelayMessageOption",
"(",
"o",
"dhcp6",
".",
"Options",
")",
"(",
"RelayMessageOption",
",",
"error",
")",
"{",
"v",
",",
"err",
":=",
"o",
".",
"GetOne",
"(",
"dhcp6",
".",
"OptionRelayMsg",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"retur... | // GetRelayMessageOption returns the Relay Message Option value, as described
// in RFC 3315, Section 22.10.
//
// The RelayMessage option carries a DHCP message in a Relay-forward or
// Relay-reply message. | [
"GetRelayMessageOption",
"returns",
"the",
"Relay",
"Message",
"Option",
"value",
"as",
"described",
"in",
"RFC",
"3315",
"Section",
"22",
".",
"10",
".",
"The",
"RelayMessage",
"option",
"carries",
"a",
"DHCP",
"message",
"in",
"a",
"Relay",
"-",
"forward",
... | 2a67805d7d0b0bad6c1103058981afdea583b459 | https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/options.go#L150-L159 |
15,951 | mdlayher/dhcp6 | dhcp6opts/options.go | GetAuthentication | func GetAuthentication(o dhcp6.Options) (*Authentication, error) {
v, err := o.GetOne(dhcp6.OptionAuth)
if err != nil {
return nil, err
}
a := new(Authentication)
err = a.UnmarshalBinary(v)
return a, err
} | go | func GetAuthentication(o dhcp6.Options) (*Authentication, error) {
v, err := o.GetOne(dhcp6.OptionAuth)
if err != nil {
return nil, err
}
a := new(Authentication)
err = a.UnmarshalBinary(v)
return a, err
} | [
"func",
"GetAuthentication",
"(",
"o",
"dhcp6",
".",
"Options",
")",
"(",
"*",
"Authentication",
",",
"error",
")",
"{",
"v",
",",
"err",
":=",
"o",
".",
"GetOne",
"(",
"dhcp6",
".",
"OptionAuth",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
... | // GetAuthentication returns the Authentication Option value, as described in
// RFC 3315, Section 22.11.
//
// The Authentication option carries authentication information to
// authenticate the identity and contents of DHCP messages. | [
"GetAuthentication",
"returns",
"the",
"Authentication",
"Option",
"value",
"as",
"described",
"in",
"RFC",
"3315",
"Section",
"22",
".",
"11",
".",
"The",
"Authentication",
"option",
"carries",
"authentication",
"information",
"to",
"authenticate",
"the",
"identity... | 2a67805d7d0b0bad6c1103058981afdea583b459 | https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/options.go#L166-L175 |
15,952 | mdlayher/dhcp6 | dhcp6opts/options.go | GetUnicast | func GetUnicast(o dhcp6.Options) (IP, error) {
v, err := o.GetOne(dhcp6.OptionUnicast)
if err != nil {
return nil, err
}
var ip IP
err = ip.UnmarshalBinary(v)
return ip, err
} | go | func GetUnicast(o dhcp6.Options) (IP, error) {
v, err := o.GetOne(dhcp6.OptionUnicast)
if err != nil {
return nil, err
}
var ip IP
err = ip.UnmarshalBinary(v)
return ip, err
} | [
"func",
"GetUnicast",
"(",
"o",
"dhcp6",
".",
"Options",
")",
"(",
"IP",
",",
"error",
")",
"{",
"v",
",",
"err",
":=",
"o",
".",
"GetOne",
"(",
"dhcp6",
".",
"OptionUnicast",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",... | // GetUnicast returns the IP from a Unicast Option value, described in RFC
// 3315, Section 22.12.
//
// The IP return value indicates a server's IPv6 address, which a client may
// use to contact the server via unicast. | [
"GetUnicast",
"returns",
"the",
"IP",
"from",
"a",
"Unicast",
"Option",
"value",
"described",
"in",
"RFC",
"3315",
"Section",
"22",
".",
"12",
".",
"The",
"IP",
"return",
"value",
"indicates",
"a",
"server",
"s",
"IPv6",
"address",
"which",
"a",
"client",
... | 2a67805d7d0b0bad6c1103058981afdea583b459 | https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/options.go#L182-L191 |
15,953 | mdlayher/dhcp6 | dhcp6opts/options.go | GetStatusCode | func GetStatusCode(o dhcp6.Options) (*StatusCode, error) {
v, err := o.GetOne(dhcp6.OptionStatusCode)
if err != nil {
return nil, err
}
s := new(StatusCode)
err = s.UnmarshalBinary(v)
return s, err
} | go | func GetStatusCode(o dhcp6.Options) (*StatusCode, error) {
v, err := o.GetOne(dhcp6.OptionStatusCode)
if err != nil {
return nil, err
}
s := new(StatusCode)
err = s.UnmarshalBinary(v)
return s, err
} | [
"func",
"GetStatusCode",
"(",
"o",
"dhcp6",
".",
"Options",
")",
"(",
"*",
"StatusCode",
",",
"error",
")",
"{",
"v",
",",
"err",
":=",
"o",
".",
"GetOne",
"(",
"dhcp6",
".",
"OptionStatusCode",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"... | // GetStatusCode returns the Status Code Option value, described in RFC 3315,
// Section 22.13.
//
// The StatusCode return value may be used to determine a code and an
// explanation for the status. | [
"GetStatusCode",
"returns",
"the",
"Status",
"Code",
"Option",
"value",
"described",
"in",
"RFC",
"3315",
"Section",
"22",
".",
"13",
".",
"The",
"StatusCode",
"return",
"value",
"may",
"be",
"used",
"to",
"determine",
"a",
"code",
"and",
"an",
"explanation"... | 2a67805d7d0b0bad6c1103058981afdea583b459 | https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/options.go#L198-L207 |
15,954 | mdlayher/dhcp6 | dhcp6opts/options.go | GetRapidCommit | func GetRapidCommit(o dhcp6.Options) error {
v, err := o.GetOne(dhcp6.OptionRapidCommit)
if err != nil {
return err
}
// Data must be completely empty; presence of the Rapid Commit option
// indicates it is requested.
if len(v) != 0 {
return dhcp6.ErrInvalidPacket
}
return nil
} | go | func GetRapidCommit(o dhcp6.Options) error {
v, err := o.GetOne(dhcp6.OptionRapidCommit)
if err != nil {
return err
}
// Data must be completely empty; presence of the Rapid Commit option
// indicates it is requested.
if len(v) != 0 {
return dhcp6.ErrInvalidPacket
}
return nil
} | [
"func",
"GetRapidCommit",
"(",
"o",
"dhcp6",
".",
"Options",
")",
"error",
"{",
"v",
",",
"err",
":=",
"o",
".",
"GetOne",
"(",
"dhcp6",
".",
"OptionRapidCommit",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// Data ... | // GetRapidCommit returns the Rapid Commit Option value, described in RFC 3315,
// Section 22.14.
//
// Nil is returned if OptionRapidCommit was present in the Options map. | [
"GetRapidCommit",
"returns",
"the",
"Rapid",
"Commit",
"Option",
"value",
"described",
"in",
"RFC",
"3315",
"Section",
"22",
".",
"14",
".",
"Nil",
"is",
"returned",
"if",
"OptionRapidCommit",
"was",
"present",
"in",
"the",
"Options",
"map",
"."
] | 2a67805d7d0b0bad6c1103058981afdea583b459 | https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/options.go#L213-L225 |
15,955 | mdlayher/dhcp6 | dhcp6opts/options.go | GetUserClass | func GetUserClass(o dhcp6.Options) (Data, error) {
v, err := o.GetOne(dhcp6.OptionUserClass)
if err != nil {
return nil, err
}
var d Data
err = d.UnmarshalBinary(v)
return d, err
} | go | func GetUserClass(o dhcp6.Options) (Data, error) {
v, err := o.GetOne(dhcp6.OptionUserClass)
if err != nil {
return nil, err
}
var d Data
err = d.UnmarshalBinary(v)
return d, err
} | [
"func",
"GetUserClass",
"(",
"o",
"dhcp6",
".",
"Options",
")",
"(",
"Data",
",",
"error",
")",
"{",
"v",
",",
"err",
":=",
"o",
".",
"GetOne",
"(",
"dhcp6",
".",
"OptionUserClass",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
... | // GetUserClass returns the User Class Option value, described in RFC 3315,
// Section 22.15.
//
// The Data structure returned contains any raw class data present in
// the option. | [
"GetUserClass",
"returns",
"the",
"User",
"Class",
"Option",
"value",
"described",
"in",
"RFC",
"3315",
"Section",
"22",
".",
"15",
".",
"The",
"Data",
"structure",
"returned",
"contains",
"any",
"raw",
"class",
"data",
"present",
"in",
"the",
"option",
"."
... | 2a67805d7d0b0bad6c1103058981afdea583b459 | https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/options.go#L232-L241 |
15,956 | mdlayher/dhcp6 | dhcp6opts/options.go | GetVendorClass | func GetVendorClass(o dhcp6.Options) (*VendorClass, error) {
v, err := o.GetOne(dhcp6.OptionVendorClass)
if err != nil {
return nil, err
}
vc := new(VendorClass)
err = vc.UnmarshalBinary(v)
return vc, err
} | go | func GetVendorClass(o dhcp6.Options) (*VendorClass, error) {
v, err := o.GetOne(dhcp6.OptionVendorClass)
if err != nil {
return nil, err
}
vc := new(VendorClass)
err = vc.UnmarshalBinary(v)
return vc, err
} | [
"func",
"GetVendorClass",
"(",
"o",
"dhcp6",
".",
"Options",
")",
"(",
"*",
"VendorClass",
",",
"error",
")",
"{",
"v",
",",
"err",
":=",
"o",
".",
"GetOne",
"(",
"dhcp6",
".",
"OptionVendorClass",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
... | // GetVendorClass returns the Vendor Class Option value, described in RFC 3315,
// Section 22.16.
//
// The VendorClass structure returned contains VendorClass in
// the option. | [
"GetVendorClass",
"returns",
"the",
"Vendor",
"Class",
"Option",
"value",
"described",
"in",
"RFC",
"3315",
"Section",
"22",
".",
"16",
".",
"The",
"VendorClass",
"structure",
"returned",
"contains",
"VendorClass",
"in",
"the",
"option",
"."
] | 2a67805d7d0b0bad6c1103058981afdea583b459 | https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/options.go#L248-L257 |
15,957 | mdlayher/dhcp6 | dhcp6opts/options.go | GetVendorOpts | func GetVendorOpts(o dhcp6.Options) (*VendorOpts, error) {
v, err := o.GetOne(dhcp6.OptionVendorOpts)
if err != nil {
return nil, err
}
vo := new(VendorOpts)
err = vo.UnmarshalBinary(v)
return vo, err
} | go | func GetVendorOpts(o dhcp6.Options) (*VendorOpts, error) {
v, err := o.GetOne(dhcp6.OptionVendorOpts)
if err != nil {
return nil, err
}
vo := new(VendorOpts)
err = vo.UnmarshalBinary(v)
return vo, err
} | [
"func",
"GetVendorOpts",
"(",
"o",
"dhcp6",
".",
"Options",
")",
"(",
"*",
"VendorOpts",
",",
"error",
")",
"{",
"v",
",",
"err",
":=",
"o",
".",
"GetOne",
"(",
"dhcp6",
".",
"OptionVendorOpts",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"... | // GetVendorOpts returns the Vendor-specific Information Option value,
// described in RFC 3315, Section 22.17.
//
// The VendorOpts structure returned contains Vendor-specific Information data
// present in the option. | [
"GetVendorOpts",
"returns",
"the",
"Vendor",
"-",
"specific",
"Information",
"Option",
"value",
"described",
"in",
"RFC",
"3315",
"Section",
"22",
".",
"17",
".",
"The",
"VendorOpts",
"structure",
"returned",
"contains",
"Vendor",
"-",
"specific",
"Information",
... | 2a67805d7d0b0bad6c1103058981afdea583b459 | https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/options.go#L264-L273 |
15,958 | mdlayher/dhcp6 | dhcp6opts/options.go | GetInterfaceID | func GetInterfaceID(o dhcp6.Options) (InterfaceID, error) {
v, err := o.GetOne(dhcp6.OptionInterfaceID)
if err != nil {
return nil, err
}
var i InterfaceID
err = i.UnmarshalBinary(v)
return i, err
} | go | func GetInterfaceID(o dhcp6.Options) (InterfaceID, error) {
v, err := o.GetOne(dhcp6.OptionInterfaceID)
if err != nil {
return nil, err
}
var i InterfaceID
err = i.UnmarshalBinary(v)
return i, err
} | [
"func",
"GetInterfaceID",
"(",
"o",
"dhcp6",
".",
"Options",
")",
"(",
"InterfaceID",
",",
"error",
")",
"{",
"v",
",",
"err",
":=",
"o",
".",
"GetOne",
"(",
"dhcp6",
".",
"OptionInterfaceID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil"... | // GetInterfaceID returns the Interface-Id Option value, described in RFC 3315,
// Section 22.18.
//
// The InterfaceID structure returned contains any raw class data present in
// the option. | [
"GetInterfaceID",
"returns",
"the",
"Interface",
"-",
"Id",
"Option",
"value",
"described",
"in",
"RFC",
"3315",
"Section",
"22",
".",
"18",
".",
"The",
"InterfaceID",
"structure",
"returned",
"contains",
"any",
"raw",
"class",
"data",
"present",
"in",
"the",
... | 2a67805d7d0b0bad6c1103058981afdea583b459 | https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/options.go#L280-L289 |
15,959 | mdlayher/dhcp6 | dhcp6opts/options.go | GetIAPD | func GetIAPD(o dhcp6.Options) ([]*IAPD, error) {
vv, err := o.Get(dhcp6.OptionIAPD)
if err != nil {
return nil, err
}
// Parse each IA_PD value
iapd := make([]*IAPD, len(vv))
for i := range vv {
iapd[i] = &IAPD{}
if err := iapd[i].UnmarshalBinary(vv[i]); err != nil {
return nil, err
}
}
return iapd, nil
} | go | func GetIAPD(o dhcp6.Options) ([]*IAPD, error) {
vv, err := o.Get(dhcp6.OptionIAPD)
if err != nil {
return nil, err
}
// Parse each IA_PD value
iapd := make([]*IAPD, len(vv))
for i := range vv {
iapd[i] = &IAPD{}
if err := iapd[i].UnmarshalBinary(vv[i]); err != nil {
return nil, err
}
}
return iapd, nil
} | [
"func",
"GetIAPD",
"(",
"o",
"dhcp6",
".",
"Options",
")",
"(",
"[",
"]",
"*",
"IAPD",
",",
"error",
")",
"{",
"vv",
",",
"err",
":=",
"o",
".",
"Get",
"(",
"dhcp6",
".",
"OptionIAPD",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
... | // GetIAPD returns the Identity Association for Prefix Delegation Option value,
// described in RFC 3633, Section 9.
//
// Multiple IAPD values may be present in a a single DHCP request. | [
"GetIAPD",
"returns",
"the",
"Identity",
"Association",
"for",
"Prefix",
"Delegation",
"Option",
"value",
"described",
"in",
"RFC",
"3633",
"Section",
"9",
".",
"Multiple",
"IAPD",
"values",
"may",
"be",
"present",
"in",
"a",
"a",
"single",
"DHCP",
"request",
... | 2a67805d7d0b0bad6c1103058981afdea583b459 | https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/options.go#L295-L311 |
15,960 | mdlayher/dhcp6 | dhcp6opts/options.go | GetIAPrefix | func GetIAPrefix(o dhcp6.Options) ([]*IAPrefix, error) {
vv, err := o.Get(dhcp6.OptionIAPrefix)
if err != nil {
return nil, err
}
// Parse each IAPrefix value
iaPrefix := make([]*IAPrefix, len(vv))
for i := range vv {
iaPrefix[i] = &IAPrefix{}
if err := iaPrefix[i].UnmarshalBinary(vv[i]); err != nil {
return nil, err
}
}
return iaPrefix, nil
} | go | func GetIAPrefix(o dhcp6.Options) ([]*IAPrefix, error) {
vv, err := o.Get(dhcp6.OptionIAPrefix)
if err != nil {
return nil, err
}
// Parse each IAPrefix value
iaPrefix := make([]*IAPrefix, len(vv))
for i := range vv {
iaPrefix[i] = &IAPrefix{}
if err := iaPrefix[i].UnmarshalBinary(vv[i]); err != nil {
return nil, err
}
}
return iaPrefix, nil
} | [
"func",
"GetIAPrefix",
"(",
"o",
"dhcp6",
".",
"Options",
")",
"(",
"[",
"]",
"*",
"IAPrefix",
",",
"error",
")",
"{",
"vv",
",",
"err",
":=",
"o",
".",
"Get",
"(",
"dhcp6",
".",
"OptionIAPrefix",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return... | // GetIAPrefix returns the Identity Association Prefix Option value, as
// described in RFC 3633, Section 10.
//
// Multiple IAPrefix values may be present in a a single DHCP request. | [
"GetIAPrefix",
"returns",
"the",
"Identity",
"Association",
"Prefix",
"Option",
"value",
"as",
"described",
"in",
"RFC",
"3633",
"Section",
"10",
".",
"Multiple",
"IAPrefix",
"values",
"may",
"be",
"present",
"in",
"a",
"a",
"single",
"DHCP",
"request",
"."
] | 2a67805d7d0b0bad6c1103058981afdea583b459 | https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/options.go#L317-L333 |
15,961 | mdlayher/dhcp6 | dhcp6opts/options.go | GetRemoteIdentifier | func GetRemoteIdentifier(o dhcp6.Options) (*RemoteIdentifier, error) {
v, err := o.GetOne(dhcp6.OptionRemoteIdentifier)
if err != nil {
return nil, err
}
r := new(RemoteIdentifier)
err = r.UnmarshalBinary(v)
return r, err
} | go | func GetRemoteIdentifier(o dhcp6.Options) (*RemoteIdentifier, error) {
v, err := o.GetOne(dhcp6.OptionRemoteIdentifier)
if err != nil {
return nil, err
}
r := new(RemoteIdentifier)
err = r.UnmarshalBinary(v)
return r, err
} | [
"func",
"GetRemoteIdentifier",
"(",
"o",
"dhcp6",
".",
"Options",
")",
"(",
"*",
"RemoteIdentifier",
",",
"error",
")",
"{",
"v",
",",
"err",
":=",
"o",
".",
"GetOne",
"(",
"dhcp6",
".",
"OptionRemoteIdentifier",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{... | // GetRemoteIdentifier returns the Remote Identifier, described in RFC 4649.
//
// This option may be added by DHCPv6 relay agents that terminate
// switched or permanent circuits and have mechanisms to identify the
// remote host end of the circuit. | [
"GetRemoteIdentifier",
"returns",
"the",
"Remote",
"Identifier",
"described",
"in",
"RFC",
"4649",
".",
"This",
"option",
"may",
"be",
"added",
"by",
"DHCPv6",
"relay",
"agents",
"that",
"terminate",
"switched",
"or",
"permanent",
"circuits",
"and",
"have",
"mec... | 2a67805d7d0b0bad6c1103058981afdea583b459 | https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/options.go#L340-L349 |
15,962 | mdlayher/dhcp6 | dhcp6opts/options.go | GetBootFileURL | func GetBootFileURL(o dhcp6.Options) (*URL, error) {
v, err := o.GetOne(dhcp6.OptionBootFileURL)
if err != nil {
return nil, err
}
u := new(URL)
err = u.UnmarshalBinary(v)
return u, err
} | go | func GetBootFileURL(o dhcp6.Options) (*URL, error) {
v, err := o.GetOne(dhcp6.OptionBootFileURL)
if err != nil {
return nil, err
}
u := new(URL)
err = u.UnmarshalBinary(v)
return u, err
} | [
"func",
"GetBootFileURL",
"(",
"o",
"dhcp6",
".",
"Options",
")",
"(",
"*",
"URL",
",",
"error",
")",
"{",
"v",
",",
"err",
":=",
"o",
".",
"GetOne",
"(",
"dhcp6",
".",
"OptionBootFileURL",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",... | // GetBootFileURL returns the Boot File URL Option value, described in RFC
// 5970, Section 3.1.
//
// The URL return value contains a URL which may be used by clients to obtain
// a boot file for PXE. | [
"GetBootFileURL",
"returns",
"the",
"Boot",
"File",
"URL",
"Option",
"value",
"described",
"in",
"RFC",
"5970",
"Section",
"3",
".",
"1",
".",
"The",
"URL",
"return",
"value",
"contains",
"a",
"URL",
"which",
"may",
"be",
"used",
"by",
"clients",
"to",
"... | 2a67805d7d0b0bad6c1103058981afdea583b459 | https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/options.go#L356-L365 |
15,963 | mdlayher/dhcp6 | dhcp6opts/options.go | GetBootFileParam | func GetBootFileParam(o dhcp6.Options) (BootFileParam, error) {
v, err := o.GetOne(dhcp6.OptionBootFileParam)
if err != nil {
return nil, err
}
var bfp BootFileParam
err = bfp.UnmarshalBinary(v)
return bfp, err
} | go | func GetBootFileParam(o dhcp6.Options) (BootFileParam, error) {
v, err := o.GetOne(dhcp6.OptionBootFileParam)
if err != nil {
return nil, err
}
var bfp BootFileParam
err = bfp.UnmarshalBinary(v)
return bfp, err
} | [
"func",
"GetBootFileParam",
"(",
"o",
"dhcp6",
".",
"Options",
")",
"(",
"BootFileParam",
",",
"error",
")",
"{",
"v",
",",
"err",
":=",
"o",
".",
"GetOne",
"(",
"dhcp6",
".",
"OptionBootFileParam",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
... | // GetBootFileParam returns the Boot File Parameters Option value, described in
// RFC 5970, Section 3.2.
//
// The Data structure returned contains any parameters needed for a boot
// file, such as a root filesystem label or a path to a configuration file for
// further chainloading. | [
"GetBootFileParam",
"returns",
"the",
"Boot",
"File",
"Parameters",
"Option",
"value",
"described",
"in",
"RFC",
"5970",
"Section",
"3",
".",
"2",
".",
"The",
"Data",
"structure",
"returned",
"contains",
"any",
"parameters",
"needed",
"for",
"a",
"boot",
"file... | 2a67805d7d0b0bad6c1103058981afdea583b459 | https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/options.go#L373-L382 |
15,964 | mdlayher/dhcp6 | dhcp6opts/options.go | GetClientArchType | func GetClientArchType(o dhcp6.Options) (ArchTypes, error) {
v, err := o.GetOne(dhcp6.OptionClientArchType)
if err != nil {
return nil, err
}
var a ArchTypes
err = a.UnmarshalBinary(v)
return a, err
} | go | func GetClientArchType(o dhcp6.Options) (ArchTypes, error) {
v, err := o.GetOne(dhcp6.OptionClientArchType)
if err != nil {
return nil, err
}
var a ArchTypes
err = a.UnmarshalBinary(v)
return a, err
} | [
"func",
"GetClientArchType",
"(",
"o",
"dhcp6",
".",
"Options",
")",
"(",
"ArchTypes",
",",
"error",
")",
"{",
"v",
",",
"err",
":=",
"o",
".",
"GetOne",
"(",
"dhcp6",
".",
"OptionClientArchType",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"... | // GetClientArchType returns the Client System Architecture Type Option value,
// described in RFC 5970, Section 3.3.
//
// The ArchTypes slice returned contains a list of one or more ArchType values.
// The first ArchType listed is the client's most preferable value. | [
"GetClientArchType",
"returns",
"the",
"Client",
"System",
"Architecture",
"Type",
"Option",
"value",
"described",
"in",
"RFC",
"5970",
"Section",
"3",
".",
"3",
".",
"The",
"ArchTypes",
"slice",
"returned",
"contains",
"a",
"list",
"of",
"one",
"or",
"more",
... | 2a67805d7d0b0bad6c1103058981afdea583b459 | https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/options.go#L389-L398 |
15,965 | mdlayher/dhcp6 | dhcp6opts/options.go | GetDNSServers | func GetDNSServers(o dhcp6.Options) (IPs, error) {
v, err := o.GetOne(dhcp6.OptionDNSServers)
if err != nil {
return nil, err
}
var ips IPs
err = ips.UnmarshalBinary(v)
return ips, err
} | go | func GetDNSServers(o dhcp6.Options) (IPs, error) {
v, err := o.GetOne(dhcp6.OptionDNSServers)
if err != nil {
return nil, err
}
var ips IPs
err = ips.UnmarshalBinary(v)
return ips, err
} | [
"func",
"GetDNSServers",
"(",
"o",
"dhcp6",
".",
"Options",
")",
"(",
"IPs",
",",
"error",
")",
"{",
"v",
",",
"err",
":=",
"o",
".",
"GetOne",
"(",
"dhcp6",
".",
"OptionDNSServers",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
... | // GetDNSServers returns the DNS Recursive Name Servers Option value, as
// described in RFC 3646, Section 3.
//
// The DNS servers are listed in the order of preference for use by the client
// resolver. | [
"GetDNSServers",
"returns",
"the",
"DNS",
"Recursive",
"Name",
"Servers",
"Option",
"value",
"as",
"described",
"in",
"RFC",
"3646",
"Section",
"3",
".",
"The",
"DNS",
"servers",
"are",
"listed",
"in",
"the",
"order",
"of",
"preference",
"for",
"use",
"by",
... | 2a67805d7d0b0bad6c1103058981afdea583b459 | https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/options.go#L421-L430 |
15,966 | mdlayher/dhcp6 | dhcp6server/mux.go | ServeDHCP | func (mux *ServeMux) ServeDHCP(w ResponseSender, r *Request) {
mux.mu.RLock()
defer mux.mu.RUnlock()
h, ok := mux.m[r.MessageType]
if !ok {
return
}
h.ServeDHCP(w, r)
} | go | func (mux *ServeMux) ServeDHCP(w ResponseSender, r *Request) {
mux.mu.RLock()
defer mux.mu.RUnlock()
h, ok := mux.m[r.MessageType]
if !ok {
return
}
h.ServeDHCP(w, r)
} | [
"func",
"(",
"mux",
"*",
"ServeMux",
")",
"ServeDHCP",
"(",
"w",
"ResponseSender",
",",
"r",
"*",
"Request",
")",
"{",
"mux",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"mux",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n",
"h",
",",
"ok",
":... | // ServeDHCP implements Handler for ServeMux, and serves a DHCP request using
// the appropriate handler for an input Request's MessageType. If the
// MessageType does not match a valid Handler, ServeDHCP does not invoke any
// handlers, ignoring a client's request. | [
"ServeDHCP",
"implements",
"Handler",
"for",
"ServeMux",
"and",
"serves",
"a",
"DHCP",
"request",
"using",
"the",
"appropriate",
"handler",
"for",
"an",
"input",
"Request",
"s",
"MessageType",
".",
"If",
"the",
"MessageType",
"does",
"not",
"match",
"a",
"vali... | 2a67805d7d0b0bad6c1103058981afdea583b459 | https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6server/mux.go#L30-L39 |
15,967 | mdlayher/dhcp6 | dhcp6server/mux.go | Handle | func (mux *ServeMux) Handle(mt dhcp6.MessageType, handler Handler) {
mux.mu.Lock()
mux.m[mt] = handler
mux.mu.Unlock()
} | go | func (mux *ServeMux) Handle(mt dhcp6.MessageType, handler Handler) {
mux.mu.Lock()
mux.m[mt] = handler
mux.mu.Unlock()
} | [
"func",
"(",
"mux",
"*",
"ServeMux",
")",
"Handle",
"(",
"mt",
"dhcp6",
".",
"MessageType",
",",
"handler",
"Handler",
")",
"{",
"mux",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"mux",
".",
"m",
"[",
"mt",
"]",
"=",
"handler",
"\n",
"mux",
".",
"... | // Handle registers a MessageType and Handler with a ServeMux, so that
// future requests with that MessageType will invoke the Handler. | [
"Handle",
"registers",
"a",
"MessageType",
"and",
"Handler",
"with",
"a",
"ServeMux",
"so",
"that",
"future",
"requests",
"with",
"that",
"MessageType",
"will",
"invoke",
"the",
"Handler",
"."
] | 2a67805d7d0b0bad6c1103058981afdea583b459 | https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6server/mux.go#L43-L47 |
15,968 | mdlayher/dhcp6 | dhcp6server/mux.go | HandleFunc | func (mux *ServeMux) HandleFunc(mt dhcp6.MessageType, handler func(ResponseSender, *Request)) {
mux.Handle(mt, HandlerFunc(handler))
} | go | func (mux *ServeMux) HandleFunc(mt dhcp6.MessageType, handler func(ResponseSender, *Request)) {
mux.Handle(mt, HandlerFunc(handler))
} | [
"func",
"(",
"mux",
"*",
"ServeMux",
")",
"HandleFunc",
"(",
"mt",
"dhcp6",
".",
"MessageType",
",",
"handler",
"func",
"(",
"ResponseSender",
",",
"*",
"Request",
")",
")",
"{",
"mux",
".",
"Handle",
"(",
"mt",
",",
"HandlerFunc",
"(",
"handler",
")",... | // HandleFunc registers a MessageType and function as a HandlerFunc with a
// ServeMux, so that future requests with that MessageType will invoke the
// HandlerFunc. | [
"HandleFunc",
"registers",
"a",
"MessageType",
"and",
"function",
"as",
"a",
"HandlerFunc",
"with",
"a",
"ServeMux",
"so",
"that",
"future",
"requests",
"with",
"that",
"MessageType",
"will",
"invoke",
"the",
"HandlerFunc",
"."
] | 2a67805d7d0b0bad6c1103058981afdea583b459 | https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6server/mux.go#L52-L54 |
15,969 | mdlayher/dhcp6 | dhcp6opts/statuscode.go | NewStatusCode | func NewStatusCode(code dhcp6.Status, message string) *StatusCode {
return &StatusCode{
Code: code,
Message: message,
}
} | go | func NewStatusCode(code dhcp6.Status, message string) *StatusCode {
return &StatusCode{
Code: code,
Message: message,
}
} | [
"func",
"NewStatusCode",
"(",
"code",
"dhcp6",
".",
"Status",
",",
"message",
"string",
")",
"*",
"StatusCode",
"{",
"return",
"&",
"StatusCode",
"{",
"Code",
":",
"code",
",",
"Message",
":",
"message",
",",
"}",
"\n",
"}"
] | // NewStatusCode creates a new StatusCode from an input Status value and a
// string message. | [
"NewStatusCode",
"creates",
"a",
"new",
"StatusCode",
"from",
"an",
"input",
"Status",
"value",
"and",
"a",
"string",
"message",
"."
] | 2a67805d7d0b0bad6c1103058981afdea583b459 | https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/statuscode.go#L26-L31 |
15,970 | mdlayher/dhcp6 | dhcp6opts/statuscode.go | MarshalBinary | func (s *StatusCode) MarshalBinary() ([]byte, error) {
// 2 bytes: status code
// N bytes: message
b := buffer.New(nil)
b.Write16(uint16(s.Code))
b.WriteBytes([]byte(s.Message))
return b.Data(), nil
} | go | func (s *StatusCode) MarshalBinary() ([]byte, error) {
// 2 bytes: status code
// N bytes: message
b := buffer.New(nil)
b.Write16(uint16(s.Code))
b.WriteBytes([]byte(s.Message))
return b.Data(), nil
} | [
"func",
"(",
"s",
"*",
"StatusCode",
")",
"MarshalBinary",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"// 2 bytes: status code",
"// N bytes: message",
"b",
":=",
"buffer",
".",
"New",
"(",
"nil",
")",
"\n",
"b",
".",
"Write16",
"(",
"uin... | // MarshalBinary allocates a byte slice containing the data from a StatusCode. | [
"MarshalBinary",
"allocates",
"a",
"byte",
"slice",
"containing",
"the",
"data",
"from",
"a",
"StatusCode",
"."
] | 2a67805d7d0b0bad6c1103058981afdea583b459 | https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/statuscode.go#L34-L41 |
15,971 | mdlayher/dhcp6 | dhcp6opts/statuscode.go | UnmarshalBinary | func (s *StatusCode) UnmarshalBinary(p []byte) error {
b := buffer.New(p)
// Too short to contain valid StatusCode
if b.Len() < 2 {
return io.ErrUnexpectedEOF
}
s.Code = dhcp6.Status(b.Read16())
s.Message = string(b.Remaining())
return nil
} | go | func (s *StatusCode) UnmarshalBinary(p []byte) error {
b := buffer.New(p)
// Too short to contain valid StatusCode
if b.Len() < 2 {
return io.ErrUnexpectedEOF
}
s.Code = dhcp6.Status(b.Read16())
s.Message = string(b.Remaining())
return nil
} | [
"func",
"(",
"s",
"*",
"StatusCode",
")",
"UnmarshalBinary",
"(",
"p",
"[",
"]",
"byte",
")",
"error",
"{",
"b",
":=",
"buffer",
".",
"New",
"(",
"p",
")",
"\n",
"// Too short to contain valid StatusCode",
"if",
"b",
".",
"Len",
"(",
")",
"<",
"2",
"... | // UnmarshalBinary unmarshals a raw byte slice into a StatusCode.
//
// If the byte slice does not contain enough data to form a valid StatusCode,
// errInvalidStatusCode is returned. | [
"UnmarshalBinary",
"unmarshals",
"a",
"raw",
"byte",
"slice",
"into",
"a",
"StatusCode",
".",
"If",
"the",
"byte",
"slice",
"does",
"not",
"contain",
"enough",
"data",
"to",
"form",
"a",
"valid",
"StatusCode",
"errInvalidStatusCode",
"is",
"returned",
"."
] | 2a67805d7d0b0bad6c1103058981afdea583b459 | https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/statuscode.go#L47-L57 |
15,972 | mdlayher/dhcp6 | options.go | Add | func (o Options) Add(key OptionCode, value encoding.BinaryMarshaler) error {
// Special case: since OptionRapidCommit actually has zero length, it is
// possible for an option key to appear with no value.
if value == nil {
o.AddRaw(key, nil)
return nil
}
b, err := value.MarshalBinary()
if err != nil {
return err
}
o.AddRaw(key, b)
return nil
} | go | func (o Options) Add(key OptionCode, value encoding.BinaryMarshaler) error {
// Special case: since OptionRapidCommit actually has zero length, it is
// possible for an option key to appear with no value.
if value == nil {
o.AddRaw(key, nil)
return nil
}
b, err := value.MarshalBinary()
if err != nil {
return err
}
o.AddRaw(key, b)
return nil
} | [
"func",
"(",
"o",
"Options",
")",
"Add",
"(",
"key",
"OptionCode",
",",
"value",
"encoding",
".",
"BinaryMarshaler",
")",
"error",
"{",
"// Special case: since OptionRapidCommit actually has zero length, it is",
"// possible for an option key to appear with no value.",
"if",
... | // Add adds a new OptionCode key and BinaryMarshaler struct's bytes to the
// Options map. | [
"Add",
"adds",
"a",
"new",
"OptionCode",
"key",
"and",
"BinaryMarshaler",
"struct",
"s",
"bytes",
"to",
"the",
"Options",
"map",
"."
] | 2a67805d7d0b0bad6c1103058981afdea583b459 | https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/options.go#L18-L33 |
15,973 | mdlayher/dhcp6 | options.go | AddRaw | func (o Options) AddRaw(key OptionCode, value []byte) {
o[key] = append(o[key], value)
} | go | func (o Options) AddRaw(key OptionCode, value []byte) {
o[key] = append(o[key], value)
} | [
"func",
"(",
"o",
"Options",
")",
"AddRaw",
"(",
"key",
"OptionCode",
",",
"value",
"[",
"]",
"byte",
")",
"{",
"o",
"[",
"key",
"]",
"=",
"append",
"(",
"o",
"[",
"key",
"]",
",",
"value",
")",
"\n",
"}"
] | // AddRaw adds a new OptionCode key and raw value byte slice to the
// Options map. | [
"AddRaw",
"adds",
"a",
"new",
"OptionCode",
"key",
"and",
"raw",
"value",
"byte",
"slice",
"to",
"the",
"Options",
"map",
"."
] | 2a67805d7d0b0bad6c1103058981afdea583b459 | https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/options.go#L37-L39 |
15,974 | mdlayher/dhcp6 | options.go | GetOne | func (o Options) GetOne(key OptionCode) ([]byte, error) {
vv, err := o.Get(key)
if err != nil {
return nil, err
}
if len(vv) != 1 {
return nil, ErrInvalidPacket
}
return vv[0], nil
} | go | func (o Options) GetOne(key OptionCode) ([]byte, error) {
vv, err := o.Get(key)
if err != nil {
return nil, err
}
if len(vv) != 1 {
return nil, ErrInvalidPacket
}
return vv[0], nil
} | [
"func",
"(",
"o",
"Options",
")",
"GetOne",
"(",
"key",
"OptionCode",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"vv",
",",
"err",
":=",
"o",
".",
"Get",
"(",
"key",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"er... | // GetOne attempts to retrieve the first and only value specified by an
// OptionCode key. GetOne should only be used for OptionCode keys that must
// have at most one value.
//
// GetOne works just like Get, but if there is more than one value for the
// OptionCode key, ErrInvalidPacket will be returned. | [
"GetOne",
"attempts",
"to",
"retrieve",
"the",
"first",
"and",
"only",
"value",
"specified",
"by",
"an",
"OptionCode",
"key",
".",
"GetOne",
"should",
"only",
"be",
"used",
"for",
"OptionCode",
"keys",
"that",
"must",
"have",
"at",
"most",
"one",
"value",
... | 2a67805d7d0b0bad6c1103058981afdea583b459 | https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/options.go#L66-L76 |
15,975 | mdlayher/dhcp6 | options.go | MarshalBinary | func (o Options) MarshalBinary() ([]byte, error) {
b := buffer.New(nil)
for _, code := range o.sortedCodes() {
for _, data := range o[code] {
// 2 bytes: option code
b.Write16(uint16(code))
// 2 bytes: option length
b.Write16(uint16(len(data)))
// N bytes: option data
b.WriteBytes(data)
}
}
return b.Data(), nil
} | go | func (o Options) MarshalBinary() ([]byte, error) {
b := buffer.New(nil)
for _, code := range o.sortedCodes() {
for _, data := range o[code] {
// 2 bytes: option code
b.Write16(uint16(code))
// 2 bytes: option length
b.Write16(uint16(len(data)))
// N bytes: option data
b.WriteBytes(data)
}
}
return b.Data(), nil
} | [
"func",
"(",
"o",
"Options",
")",
"MarshalBinary",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"b",
":=",
"buffer",
".",
"New",
"(",
"nil",
")",
"\n",
"for",
"_",
",",
"code",
":=",
"range",
"o",
".",
"sortedCodes",
"(",
")",
"{",
... | // MarshalBinary allocates a buffer and writes options in their DHCPv6 binary
// format into the buffer. | [
"MarshalBinary",
"allocates",
"a",
"buffer",
"and",
"writes",
"options",
"in",
"their",
"DHCPv6",
"binary",
"format",
"into",
"the",
"buffer",
"."
] | 2a67805d7d0b0bad6c1103058981afdea583b459 | https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/options.go#L80-L95 |
15,976 | mdlayher/dhcp6 | options.go | UnmarshalBinary | func (o *Options) UnmarshalBinary(p []byte) error {
buf := buffer.New(p)
*o = make(Options)
for buf.Len() >= 4 {
// 2 bytes: option code
// 2 bytes: option length n
// n bytes: data
code := OptionCode(buf.Read16())
length := buf.Read16()
// N bytes: option data
data := buf.Consume(int(length))
if data == nil {
return ErrInvalidOptions
}
data = data[:int(length):int(length)]
o.AddRaw(code, data)
}
// Report error for any trailing bytes
if buf.Len() != 0 {
return ErrInvalidOptions
}
return nil
} | go | func (o *Options) UnmarshalBinary(p []byte) error {
buf := buffer.New(p)
*o = make(Options)
for buf.Len() >= 4 {
// 2 bytes: option code
// 2 bytes: option length n
// n bytes: data
code := OptionCode(buf.Read16())
length := buf.Read16()
// N bytes: option data
data := buf.Consume(int(length))
if data == nil {
return ErrInvalidOptions
}
data = data[:int(length):int(length)]
o.AddRaw(code, data)
}
// Report error for any trailing bytes
if buf.Len() != 0 {
return ErrInvalidOptions
}
return nil
} | [
"func",
"(",
"o",
"*",
"Options",
")",
"UnmarshalBinary",
"(",
"p",
"[",
"]",
"byte",
")",
"error",
"{",
"buf",
":=",
"buffer",
".",
"New",
"(",
"p",
")",
"\n",
"*",
"o",
"=",
"make",
"(",
"Options",
")",
"\n\n",
"for",
"buf",
".",
"Len",
"(",
... | // UnmarshalBinary fills opts with option codes and corresponding values from
// an input byte slice.
//
// It is used with various different types to enable parsing of both top-level
// options, and options embedded within other options. If options data is
// malformed, it returns ErrInvalidOptions. | [
"UnmarshalBinary",
"fills",
"opts",
"with",
"option",
"codes",
"and",
"corresponding",
"values",
"from",
"an",
"input",
"byte",
"slice",
".",
"It",
"is",
"used",
"with",
"various",
"different",
"types",
"to",
"enable",
"parsing",
"of",
"both",
"top",
"-",
"l... | 2a67805d7d0b0bad6c1103058981afdea583b459 | https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/options.go#L103-L129 |
15,977 | mdlayher/dhcp6 | dhcp6opts/miscoptions.go | MarshalBinary | func (oro OptionRequestOption) MarshalBinary() ([]byte, error) {
b := buffer.New(nil)
for _, opt := range oro {
b.Write16(uint16(opt))
}
return b.Data(), nil
} | go | func (oro OptionRequestOption) MarshalBinary() ([]byte, error) {
b := buffer.New(nil)
for _, opt := range oro {
b.Write16(uint16(opt))
}
return b.Data(), nil
} | [
"func",
"(",
"oro",
"OptionRequestOption",
")",
"MarshalBinary",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"b",
":=",
"buffer",
".",
"New",
"(",
"nil",
")",
"\n",
"for",
"_",
",",
"opt",
":=",
"range",
"oro",
"{",
"b",
".",
"Write1... | // MarshalBinary allocates a byte slice containing the data from a OptionRequestOption. | [
"MarshalBinary",
"allocates",
"a",
"byte",
"slice",
"containing",
"the",
"data",
"from",
"a",
"OptionRequestOption",
"."
] | 2a67805d7d0b0bad6c1103058981afdea583b459 | https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/miscoptions.go#L21-L27 |
15,978 | mdlayher/dhcp6 | dhcp6opts/miscoptions.go | UnmarshalBinary | func (oro *OptionRequestOption) UnmarshalBinary(p []byte) error {
b := buffer.New(p)
// Length must be divisible by 2.
if b.Len()%2 != 0 {
return io.ErrUnexpectedEOF
}
// Fill slice by parsing every two bytes using index i.
*oro = make(OptionRequestOption, 0, b.Len()/2)
for b.Len() > 1 {
*oro = append(*oro, dhcp6.OptionCode(b.Read16()))
}
return nil
} | go | func (oro *OptionRequestOption) UnmarshalBinary(p []byte) error {
b := buffer.New(p)
// Length must be divisible by 2.
if b.Len()%2 != 0 {
return io.ErrUnexpectedEOF
}
// Fill slice by parsing every two bytes using index i.
*oro = make(OptionRequestOption, 0, b.Len()/2)
for b.Len() > 1 {
*oro = append(*oro, dhcp6.OptionCode(b.Read16()))
}
return nil
} | [
"func",
"(",
"oro",
"*",
"OptionRequestOption",
")",
"UnmarshalBinary",
"(",
"p",
"[",
"]",
"byte",
")",
"error",
"{",
"b",
":=",
"buffer",
".",
"New",
"(",
"p",
")",
"\n",
"// Length must be divisible by 2.",
"if",
"b",
".",
"Len",
"(",
")",
"%",
"2",... | // UnmarshalBinary unmarshals a raw byte slice into a OptionRequestOption.
//
// If the length of byte slice is not be be divisible by 2,
// errInvalidOptionRequest is returned. | [
"UnmarshalBinary",
"unmarshals",
"a",
"raw",
"byte",
"slice",
"into",
"a",
"OptionRequestOption",
".",
"If",
"the",
"length",
"of",
"byte",
"slice",
"is",
"not",
"be",
"be",
"divisible",
"by",
"2",
"errInvalidOptionRequest",
"is",
"returned",
"."
] | 2a67805d7d0b0bad6c1103058981afdea583b459 | https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/miscoptions.go#L33-L46 |
15,979 | mdlayher/dhcp6 | dhcp6opts/miscoptions.go | UnmarshalBinary | func (p *Preference) UnmarshalBinary(b []byte) error {
if len(b) != 1 {
return io.ErrUnexpectedEOF
}
*p = Preference(b[0])
return nil
} | go | func (p *Preference) UnmarshalBinary(b []byte) error {
if len(b) != 1 {
return io.ErrUnexpectedEOF
}
*p = Preference(b[0])
return nil
} | [
"func",
"(",
"p",
"*",
"Preference",
")",
"UnmarshalBinary",
"(",
"b",
"[",
"]",
"byte",
")",
"error",
"{",
"if",
"len",
"(",
"b",
")",
"!=",
"1",
"{",
"return",
"io",
".",
"ErrUnexpectedEOF",
"\n",
"}",
"\n\n",
"*",
"p",
"=",
"Preference",
"(",
... | // UnmarshalBinary unmarshals a raw byte slice into a Preference.
//
// If the byte slice is not exactly 1 byte in length, io.ErrUnexpectedEOF is
// returned. | [
"UnmarshalBinary",
"unmarshals",
"a",
"raw",
"byte",
"slice",
"into",
"a",
"Preference",
".",
"If",
"the",
"byte",
"slice",
"is",
"not",
"exactly",
"1",
"byte",
"in",
"length",
"io",
".",
"ErrUnexpectedEOF",
"is",
"returned",
"."
] | 2a67805d7d0b0bad6c1103058981afdea583b459 | https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/miscoptions.go#L63-L70 |
15,980 | mdlayher/dhcp6 | dhcp6opts/miscoptions.go | MarshalBinary | func (t ElapsedTime) MarshalBinary() ([]byte, error) {
b := buffer.New(nil)
unit := 10 * time.Millisecond
// The elapsed time value is an unsigned, 16 bit integer.
// The client uses the value 0xffff to represent any
// elapsed time values greater than the largest time value
// that can be represented in the Elapsed Time option.
if max := time.Duration(math.MaxUint16) * unit; time.Duration(t) > max {
t = ElapsedTime(max)
}
b.Write16(uint16(time.Duration(t) / unit))
return b.Data(), nil
} | go | func (t ElapsedTime) MarshalBinary() ([]byte, error) {
b := buffer.New(nil)
unit := 10 * time.Millisecond
// The elapsed time value is an unsigned, 16 bit integer.
// The client uses the value 0xffff to represent any
// elapsed time values greater than the largest time value
// that can be represented in the Elapsed Time option.
if max := time.Duration(math.MaxUint16) * unit; time.Duration(t) > max {
t = ElapsedTime(max)
}
b.Write16(uint16(time.Duration(t) / unit))
return b.Data(), nil
} | [
"func",
"(",
"t",
"ElapsedTime",
")",
"MarshalBinary",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"b",
":=",
"buffer",
".",
"New",
"(",
"nil",
")",
"\n\n",
"unit",
":=",
"10",
"*",
"time",
".",
"Millisecond",
"\n",
"// The elapsed time ... | // MarshalBinary allocates a byte slice containing the data from an
// ElapsedTime. | [
"MarshalBinary",
"allocates",
"a",
"byte",
"slice",
"containing",
"the",
"data",
"from",
"an",
"ElapsedTime",
"."
] | 2a67805d7d0b0bad6c1103058981afdea583b459 | https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/miscoptions.go#L81-L94 |
15,981 | mdlayher/dhcp6 | dhcp6opts/miscoptions.go | UnmarshalBinary | func (t *ElapsedTime) UnmarshalBinary(p []byte) error {
b := buffer.New(p)
if b.Len() != 2 {
return io.ErrUnexpectedEOF
}
// Time is reported in hundredths of seconds, so we convert it to a more
// manageable milliseconds
*t = ElapsedTime(time.Duration(b.Read16()) * 10 * time.Millisecond)
return nil
} | go | func (t *ElapsedTime) UnmarshalBinary(p []byte) error {
b := buffer.New(p)
if b.Len() != 2 {
return io.ErrUnexpectedEOF
}
// Time is reported in hundredths of seconds, so we convert it to a more
// manageable milliseconds
*t = ElapsedTime(time.Duration(b.Read16()) * 10 * time.Millisecond)
return nil
} | [
"func",
"(",
"t",
"*",
"ElapsedTime",
")",
"UnmarshalBinary",
"(",
"p",
"[",
"]",
"byte",
")",
"error",
"{",
"b",
":=",
"buffer",
".",
"New",
"(",
"p",
")",
"\n",
"if",
"b",
".",
"Len",
"(",
")",
"!=",
"2",
"{",
"return",
"io",
".",
"ErrUnexpec... | // UnmarshalBinary unmarshals a raw byte slice into a ElapsedTime.
//
// If the byte slice is not exactly 2 bytes in length, io.ErrUnexpectedEOF is
// returned. | [
"UnmarshalBinary",
"unmarshals",
"a",
"raw",
"byte",
"slice",
"into",
"a",
"ElapsedTime",
".",
"If",
"the",
"byte",
"slice",
"is",
"not",
"exactly",
"2",
"bytes",
"in",
"length",
"io",
".",
"ErrUnexpectedEOF",
"is",
"returned",
"."
] | 2a67805d7d0b0bad6c1103058981afdea583b459 | https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/miscoptions.go#L100-L110 |
15,982 | mdlayher/dhcp6 | dhcp6opts/miscoptions.go | MarshalBinary | func (i IP) MarshalBinary() ([]byte, error) {
ip := make([]byte, net.IPv6len)
copy(ip, i)
return ip, nil
} | go | func (i IP) MarshalBinary() ([]byte, error) {
ip := make([]byte, net.IPv6len)
copy(ip, i)
return ip, nil
} | [
"func",
"(",
"i",
"IP",
")",
"MarshalBinary",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"ip",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"net",
".",
"IPv6len",
")",
"\n",
"copy",
"(",
"ip",
",",
"i",
")",
"\n",
"return",
"ip",
... | // MarshalBinary allocates a byte slice containing the data from a IP. | [
"MarshalBinary",
"allocates",
"a",
"byte",
"slice",
"containing",
"the",
"data",
"from",
"a",
"IP",
"."
] | 2a67805d7d0b0bad6c1103058981afdea583b459 | https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/miscoptions.go#L117-L121 |
15,983 | mdlayher/dhcp6 | dhcp6opts/miscoptions.go | UnmarshalBinary | func (i *IP) UnmarshalBinary(b []byte) error {
if len(b) != net.IPv6len {
return io.ErrUnexpectedEOF
}
if ip := net.IP(b); ip.To4() != nil {
return io.ErrUnexpectedEOF
}
*i = make(IP, net.IPv6len)
copy(*i, b)
return nil
} | go | func (i *IP) UnmarshalBinary(b []byte) error {
if len(b) != net.IPv6len {
return io.ErrUnexpectedEOF
}
if ip := net.IP(b); ip.To4() != nil {
return io.ErrUnexpectedEOF
}
*i = make(IP, net.IPv6len)
copy(*i, b)
return nil
} | [
"func",
"(",
"i",
"*",
"IP",
")",
"UnmarshalBinary",
"(",
"b",
"[",
"]",
"byte",
")",
"error",
"{",
"if",
"len",
"(",
"b",
")",
"!=",
"net",
".",
"IPv6len",
"{",
"return",
"io",
".",
"ErrUnexpectedEOF",
"\n",
"}",
"\n\n",
"if",
"ip",
":=",
"net",... | // UnmarshalBinary unmarshals a raw byte slice into an IP.
//
// If the byte slice is not an IPv6 address, io.ErrUnexpectedEOF is
// returned. | [
"UnmarshalBinary",
"unmarshals",
"a",
"raw",
"byte",
"slice",
"into",
"an",
"IP",
".",
"If",
"the",
"byte",
"slice",
"is",
"not",
"an",
"IPv6",
"address",
"io",
".",
"ErrUnexpectedEOF",
"is",
"returned",
"."
] | 2a67805d7d0b0bad6c1103058981afdea583b459 | https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/miscoptions.go#L127-L139 |
15,984 | mdlayher/dhcp6 | dhcp6opts/miscoptions.go | MarshalBinary | func (i IPs) MarshalBinary() ([]byte, error) {
ips := make([]byte, 0, len(i)*net.IPv6len)
for _, ip := range i {
ips = append(ips, ip.To16()...)
}
return ips, nil
} | go | func (i IPs) MarshalBinary() ([]byte, error) {
ips := make([]byte, 0, len(i)*net.IPv6len)
for _, ip := range i {
ips = append(ips, ip.To16()...)
}
return ips, nil
} | [
"func",
"(",
"i",
"IPs",
")",
"MarshalBinary",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"ips",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"0",
",",
"len",
"(",
"i",
")",
"*",
"net",
".",
"IPv6len",
")",
"\n",
"for",
"_",
",",... | // MarshalBinary allocates a byte slice containing the consecutive data of all
// IPs. | [
"MarshalBinary",
"allocates",
"a",
"byte",
"slice",
"containing",
"the",
"consecutive",
"data",
"of",
"all",
"IPs",
"."
] | 2a67805d7d0b0bad6c1103058981afdea583b459 | https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/miscoptions.go#L146-L152 |
15,985 | mdlayher/dhcp6 | dhcp6opts/miscoptions.go | UnmarshalBinary | func (i *IPs) UnmarshalBinary(p []byte) error {
b := buffer.New(p)
if b.Len()%net.IPv6len != 0 || b.Len() == 0 {
return io.ErrUnexpectedEOF
}
*i = make(IPs, 0, b.Len()/net.IPv6len)
for b.Len() > 0 {
ip := make(net.IP, net.IPv6len)
b.ReadBytes(ip)
*i = append(*i, ip)
}
return nil
} | go | func (i *IPs) UnmarshalBinary(p []byte) error {
b := buffer.New(p)
if b.Len()%net.IPv6len != 0 || b.Len() == 0 {
return io.ErrUnexpectedEOF
}
*i = make(IPs, 0, b.Len()/net.IPv6len)
for b.Len() > 0 {
ip := make(net.IP, net.IPv6len)
b.ReadBytes(ip)
*i = append(*i, ip)
}
return nil
} | [
"func",
"(",
"i",
"*",
"IPs",
")",
"UnmarshalBinary",
"(",
"p",
"[",
"]",
"byte",
")",
"error",
"{",
"b",
":=",
"buffer",
".",
"New",
"(",
"p",
")",
"\n",
"if",
"b",
".",
"Len",
"(",
")",
"%",
"net",
".",
"IPv6len",
"!=",
"0",
"||",
"b",
".... | // UnmarshalBinary unmarshals a raw byte slice into a list of IPs.
//
// If the byte slice contains any non-IPv6 addresses, io.ErrUnexpectedEOF is
// returned. | [
"UnmarshalBinary",
"unmarshals",
"a",
"raw",
"byte",
"slice",
"into",
"a",
"list",
"of",
"IPs",
".",
"If",
"the",
"byte",
"slice",
"contains",
"any",
"non",
"-",
"IPv6",
"addresses",
"io",
".",
"ErrUnexpectedEOF",
"is",
"returned",
"."
] | 2a67805d7d0b0bad6c1103058981afdea583b459 | https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/miscoptions.go#L158-L171 |
15,986 | mdlayher/dhcp6 | dhcp6opts/miscoptions.go | MarshalBinary | func (d Data) MarshalBinary() ([]byte, error) {
// Count number of bytes needed to allocate at once
var c int
for _, dd := range d {
c += 2 + len(dd)
}
b := buffer.New(nil)
d.Marshal(b)
return b.Data(), nil
} | go | func (d Data) MarshalBinary() ([]byte, error) {
// Count number of bytes needed to allocate at once
var c int
for _, dd := range d {
c += 2 + len(dd)
}
b := buffer.New(nil)
d.Marshal(b)
return b.Data(), nil
} | [
"func",
"(",
"d",
"Data",
")",
"MarshalBinary",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"// Count number of bytes needed to allocate at once",
"var",
"c",
"int",
"\n",
"for",
"_",
",",
"dd",
":=",
"range",
"d",
"{",
"c",
"+=",
"2",
"+"... | // MarshalBinary allocates a byte slice containing the data from a Data
// structure. | [
"MarshalBinary",
"allocates",
"a",
"byte",
"slice",
"containing",
"the",
"data",
"from",
"a",
"Data",
"structure",
"."
] | 2a67805d7d0b0bad6c1103058981afdea583b459 | https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/miscoptions.go#L179-L189 |
15,987 | mdlayher/dhcp6 | dhcp6opts/miscoptions.go | Marshal | func (d Data) Marshal(b *buffer.Buffer) {
for _, dd := range d {
// 2 byte: length of data
b.Write16(uint16(len(dd)))
// N bytes: actual raw data
b.WriteBytes(dd)
}
} | go | func (d Data) Marshal(b *buffer.Buffer) {
for _, dd := range d {
// 2 byte: length of data
b.Write16(uint16(len(dd)))
// N bytes: actual raw data
b.WriteBytes(dd)
}
} | [
"func",
"(",
"d",
"Data",
")",
"Marshal",
"(",
"b",
"*",
"buffer",
".",
"Buffer",
")",
"{",
"for",
"_",
",",
"dd",
":=",
"range",
"d",
"{",
"// 2 byte: length of data",
"b",
".",
"Write16",
"(",
"uint16",
"(",
"len",
"(",
"dd",
")",
")",
")",
"\n... | // Marshal marshals to a given buffer from a Data structure. | [
"Marshal",
"marshals",
"to",
"a",
"given",
"buffer",
"from",
"a",
"Data",
"structure",
"."
] | 2a67805d7d0b0bad6c1103058981afdea583b459 | https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/miscoptions.go#L192-L200 |
15,988 | mdlayher/dhcp6 | dhcp6opts/miscoptions.go | UnmarshalBinary | func (d *Data) UnmarshalBinary(p []byte) error {
b := buffer.New(p)
return d.Unmarshal(b)
} | go | func (d *Data) UnmarshalBinary(p []byte) error {
b := buffer.New(p)
return d.Unmarshal(b)
} | [
"func",
"(",
"d",
"*",
"Data",
")",
"UnmarshalBinary",
"(",
"p",
"[",
"]",
"byte",
")",
"error",
"{",
"b",
":=",
"buffer",
".",
"New",
"(",
"p",
")",
"\n",
"return",
"d",
".",
"Unmarshal",
"(",
"b",
")",
"\n",
"}"
] | // UnmarshalBinary unmarshals a raw byte slice into a Data structure. | [
"UnmarshalBinary",
"unmarshals",
"a",
"raw",
"byte",
"slice",
"into",
"a",
"Data",
"structure",
"."
] | 2a67805d7d0b0bad6c1103058981afdea583b459 | https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/miscoptions.go#L203-L206 |
15,989 | mdlayher/dhcp6 | dhcp6opts/miscoptions.go | MarshalBinary | func (u URL) MarshalBinary() ([]byte, error) {
uu := url.URL(u)
return []byte(uu.String()), nil
} | go | func (u URL) MarshalBinary() ([]byte, error) {
uu := url.URL(u)
return []byte(uu.String()), nil
} | [
"func",
"(",
"u",
"URL",
")",
"MarshalBinary",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"uu",
":=",
"url",
".",
"URL",
"(",
"u",
")",
"\n",
"return",
"[",
"]",
"byte",
"(",
"uu",
".",
"String",
"(",
")",
")",
",",
"nil",
"\n... | // MarshalBinary allocates a byte slice containing the data from a URL. | [
"MarshalBinary",
"allocates",
"a",
"byte",
"slice",
"containing",
"the",
"data",
"from",
"a",
"URL",
"."
] | 2a67805d7d0b0bad6c1103058981afdea583b459 | https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/miscoptions.go#L243-L246 |
15,990 | mdlayher/dhcp6 | dhcp6opts/miscoptions.go | UnmarshalBinary | func (u *URL) UnmarshalBinary(b []byte) error {
uu, err := url.Parse(string(b))
if err != nil {
return err
}
*u = URL(*uu)
return nil
} | go | func (u *URL) UnmarshalBinary(b []byte) error {
uu, err := url.Parse(string(b))
if err != nil {
return err
}
*u = URL(*uu)
return nil
} | [
"func",
"(",
"u",
"*",
"URL",
")",
"UnmarshalBinary",
"(",
"b",
"[",
"]",
"byte",
")",
"error",
"{",
"uu",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"string",
"(",
"b",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"... | // UnmarshalBinary unmarshals a raw byte slice into an URL.
//
// If the byte slice is not an URLv6 address, io.ErrUnexpectedEOF is
// returned. | [
"UnmarshalBinary",
"unmarshals",
"a",
"raw",
"byte",
"slice",
"into",
"an",
"URL",
".",
"If",
"the",
"byte",
"slice",
"is",
"not",
"an",
"URLv6",
"address",
"io",
".",
"ErrUnexpectedEOF",
"is",
"returned",
"."
] | 2a67805d7d0b0bad6c1103058981afdea583b459 | https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/miscoptions.go#L252-L260 |
15,991 | mdlayher/dhcp6 | dhcp6opts/miscoptions.go | MarshalBinary | func (a ArchTypes) MarshalBinary() ([]byte, error) {
b := buffer.New(nil)
for _, aType := range a {
b.Write16(uint16(aType))
}
return b.Data(), nil
} | go | func (a ArchTypes) MarshalBinary() ([]byte, error) {
b := buffer.New(nil)
for _, aType := range a {
b.Write16(uint16(aType))
}
return b.Data(), nil
} | [
"func",
"(",
"a",
"ArchTypes",
")",
"MarshalBinary",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"b",
":=",
"buffer",
".",
"New",
"(",
"nil",
")",
"\n",
"for",
"_",
",",
"aType",
":=",
"range",
"a",
"{",
"b",
".",
"Write16",
"(",
... | // MarshalBinary allocates a byte slice containing the data from ArchTypes. | [
"MarshalBinary",
"allocates",
"a",
"byte",
"slice",
"containing",
"the",
"data",
"from",
"ArchTypes",
"."
] | 2a67805d7d0b0bad6c1103058981afdea583b459 | https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/miscoptions.go#L268-L275 |
15,992 | mdlayher/dhcp6 | dhcp6opts/miscoptions.go | UnmarshalBinary | func (a *ArchTypes) UnmarshalBinary(p []byte) error {
b := buffer.New(p)
// Length must be at least 2, and divisible by 2.
if b.Len() < 2 || b.Len()%2 != 0 {
return io.ErrUnexpectedEOF
}
// Allocate ArchTypes at once and unpack every two bytes into an element
arch := make(ArchTypes, 0, b.Len()/2)
for b.Len() > 1 {
arch = append(arch, ArchType(b.Read16()))
}
*a = arch
return nil
} | go | func (a *ArchTypes) UnmarshalBinary(p []byte) error {
b := buffer.New(p)
// Length must be at least 2, and divisible by 2.
if b.Len() < 2 || b.Len()%2 != 0 {
return io.ErrUnexpectedEOF
}
// Allocate ArchTypes at once and unpack every two bytes into an element
arch := make(ArchTypes, 0, b.Len()/2)
for b.Len() > 1 {
arch = append(arch, ArchType(b.Read16()))
}
*a = arch
return nil
} | [
"func",
"(",
"a",
"*",
"ArchTypes",
")",
"UnmarshalBinary",
"(",
"p",
"[",
"]",
"byte",
")",
"error",
"{",
"b",
":=",
"buffer",
".",
"New",
"(",
"p",
")",
"\n",
"// Length must be at least 2, and divisible by 2.",
"if",
"b",
".",
"Len",
"(",
")",
"<",
... | // UnmarshalBinary unmarshals a raw byte slice into an ArchTypes slice.
//
// If the byte slice is less than 2 bytes in length, or is not a length that
// is divisible by 2, io.ErrUnexpectedEOF is returned. | [
"UnmarshalBinary",
"unmarshals",
"a",
"raw",
"byte",
"slice",
"into",
"an",
"ArchTypes",
"slice",
".",
"If",
"the",
"byte",
"slice",
"is",
"less",
"than",
"2",
"bytes",
"in",
"length",
"or",
"is",
"not",
"a",
"length",
"that",
"is",
"divisible",
"by",
"2... | 2a67805d7d0b0bad6c1103058981afdea583b459 | https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/miscoptions.go#L281-L296 |
15,993 | mdlayher/dhcp6 | dhcp6opts/miscoptions.go | MarshalBinary | func (n *NII) MarshalBinary() ([]byte, error) {
b := make([]byte, 3)
b[0] = n.Type
b[1] = n.Major
b[2] = n.Minor
return b, nil
} | go | func (n *NII) MarshalBinary() ([]byte, error) {
b := make([]byte, 3)
b[0] = n.Type
b[1] = n.Major
b[2] = n.Minor
return b, nil
} | [
"func",
"(",
"n",
"*",
"NII",
")",
"MarshalBinary",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"b",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"3",
")",
"\n\n",
"b",
"[",
"0",
"]",
"=",
"n",
".",
"Type",
"\n",
"b",
"[",
"1",
... | // MarshalBinary allocates a byte slice containing the data from a NII. | [
"MarshalBinary",
"allocates",
"a",
"byte",
"slice",
"containing",
"the",
"data",
"from",
"a",
"NII",
"."
] | 2a67805d7d0b0bad6c1103058981afdea583b459 | https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/miscoptions.go#L315-L323 |
15,994 | mdlayher/dhcp6 | dhcp6opts/miscoptions.go | UnmarshalBinary | func (n *NII) UnmarshalBinary(b []byte) error {
// Length must be exactly 3
if len(b) != 3 {
return io.ErrUnexpectedEOF
}
n.Type = b[0]
n.Major = b[1]
n.Minor = b[2]
return nil
} | go | func (n *NII) UnmarshalBinary(b []byte) error {
// Length must be exactly 3
if len(b) != 3 {
return io.ErrUnexpectedEOF
}
n.Type = b[0]
n.Major = b[1]
n.Minor = b[2]
return nil
} | [
"func",
"(",
"n",
"*",
"NII",
")",
"UnmarshalBinary",
"(",
"b",
"[",
"]",
"byte",
")",
"error",
"{",
"// Length must be exactly 3",
"if",
"len",
"(",
"b",
")",
"!=",
"3",
"{",
"return",
"io",
".",
"ErrUnexpectedEOF",
"\n",
"}",
"\n\n",
"n",
".",
"Typ... | // UnmarshalBinary unmarshals a raw byte slice into a NII.
//
// If the byte slice is not exactly 3 bytes in length, io.ErrUnexpectedEOF
// is returned. | [
"UnmarshalBinary",
"unmarshals",
"a",
"raw",
"byte",
"slice",
"into",
"a",
"NII",
".",
"If",
"the",
"byte",
"slice",
"is",
"not",
"exactly",
"3",
"bytes",
"in",
"length",
"io",
".",
"ErrUnexpectedEOF",
"is",
"returned",
"."
] | 2a67805d7d0b0bad6c1103058981afdea583b459 | https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/miscoptions.go#L329-L340 |
15,995 | mdlayher/dhcp6 | dhcp6opts/miscoptions.go | UnmarshalBinary | func (r *RelayMessageOption) UnmarshalBinary(b []byte) error {
*r = make([]byte, len(b))
copy(*r, b)
return nil
} | go | func (r *RelayMessageOption) UnmarshalBinary(b []byte) error {
*r = make([]byte, len(b))
copy(*r, b)
return nil
} | [
"func",
"(",
"r",
"*",
"RelayMessageOption",
")",
"UnmarshalBinary",
"(",
"b",
"[",
"]",
"byte",
")",
"error",
"{",
"*",
"r",
"=",
"make",
"(",
"[",
"]",
"byte",
",",
"len",
"(",
"b",
")",
")",
"\n",
"copy",
"(",
"*",
"r",
",",
"b",
")",
"\n"... | // UnmarshalBinary unmarshals a raw byte slice into a RelayMessageOption. | [
"UnmarshalBinary",
"unmarshals",
"a",
"raw",
"byte",
"slice",
"into",
"a",
"RelayMessageOption",
"."
] | 2a67805d7d0b0bad6c1103058981afdea583b459 | https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/miscoptions.go#L355-L359 |
15,996 | mdlayher/dhcp6 | dhcp6opts/miscoptions.go | UnmarshalBinary | func (i *InterfaceID) UnmarshalBinary(b []byte) error {
*i = make([]byte, len(b))
copy(*i, b)
return nil
} | go | func (i *InterfaceID) UnmarshalBinary(b []byte) error {
*i = make([]byte, len(b))
copy(*i, b)
return nil
} | [
"func",
"(",
"i",
"*",
"InterfaceID",
")",
"UnmarshalBinary",
"(",
"b",
"[",
"]",
"byte",
")",
"error",
"{",
"*",
"i",
"=",
"make",
"(",
"[",
"]",
"byte",
",",
"len",
"(",
"b",
")",
")",
"\n",
"copy",
"(",
"*",
"i",
",",
"b",
")",
"\n",
"re... | // UnmarshalBinary unmarshals a raw byte slice into a InterfaceID. | [
"UnmarshalBinary",
"unmarshals",
"a",
"raw",
"byte",
"slice",
"into",
"a",
"InterfaceID",
"."
] | 2a67805d7d0b0bad6c1103058981afdea583b459 | https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/miscoptions.go#L418-L422 |
15,997 | mdlayher/dhcp6 | dhcp6opts/miscoptions.go | MarshalBinary | func (bfp BootFileParam) MarshalBinary() ([]byte, error) {
// Convert []string to [][]byte.
bb := make(Data, 0, len(bfp))
for _, param := range bfp {
bb = append(bb, []byte(param))
}
return bb.MarshalBinary()
} | go | func (bfp BootFileParam) MarshalBinary() ([]byte, error) {
// Convert []string to [][]byte.
bb := make(Data, 0, len(bfp))
for _, param := range bfp {
bb = append(bb, []byte(param))
}
return bb.MarshalBinary()
} | [
"func",
"(",
"bfp",
"BootFileParam",
")",
"MarshalBinary",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"// Convert []string to [][]byte.",
"bb",
":=",
"make",
"(",
"Data",
",",
"0",
",",
"len",
"(",
"bfp",
")",
")",
"\n",
"for",
"_",
","... | // MarshalBinary allocates a byte slice containing the data from a
// BootFileParam. | [
"MarshalBinary",
"allocates",
"a",
"byte",
"slice",
"containing",
"the",
"data",
"from",
"a",
"BootFileParam",
"."
] | 2a67805d7d0b0bad6c1103058981afdea583b459 | https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/miscoptions.go#L429-L436 |
15,998 | mdlayher/dhcp6 | dhcp6opts/miscoptions.go | UnmarshalBinary | func (bfp *BootFileParam) UnmarshalBinary(b []byte) error {
var d Data
if err := (&d).UnmarshalBinary(b); err != nil {
return err
}
// Convert [][]byte to []string.
*bfp = make([]string, 0, len(d))
for _, param := range d {
*bfp = append(*bfp, string(param))
}
return nil
} | go | func (bfp *BootFileParam) UnmarshalBinary(b []byte) error {
var d Data
if err := (&d).UnmarshalBinary(b); err != nil {
return err
}
// Convert [][]byte to []string.
*bfp = make([]string, 0, len(d))
for _, param := range d {
*bfp = append(*bfp, string(param))
}
return nil
} | [
"func",
"(",
"bfp",
"*",
"BootFileParam",
")",
"UnmarshalBinary",
"(",
"b",
"[",
"]",
"byte",
")",
"error",
"{",
"var",
"d",
"Data",
"\n",
"if",
"err",
":=",
"(",
"&",
"d",
")",
".",
"UnmarshalBinary",
"(",
"b",
")",
";",
"err",
"!=",
"nil",
"{",... | // UnmarshalBinary unmarshals a raw byte slice into a BootFileParam. | [
"UnmarshalBinary",
"unmarshals",
"a",
"raw",
"byte",
"slice",
"into",
"a",
"BootFileParam",
"."
] | 2a67805d7d0b0bad6c1103058981afdea583b459 | https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/miscoptions.go#L439-L450 |
15,999 | mdlayher/dhcp6 | dhcp6opts/iapd.go | NewIAPD | func NewIAPD(iaid [4]byte, t1 time.Duration, t2 time.Duration, options dhcp6.Options) *IAPD {
if options == nil {
options = make(dhcp6.Options)
}
return &IAPD{
IAID: iaid,
T1: t1,
T2: t2,
Options: options,
}
} | go | func NewIAPD(iaid [4]byte, t1 time.Duration, t2 time.Duration, options dhcp6.Options) *IAPD {
if options == nil {
options = make(dhcp6.Options)
}
return &IAPD{
IAID: iaid,
T1: t1,
T2: t2,
Options: options,
}
} | [
"func",
"NewIAPD",
"(",
"iaid",
"[",
"4",
"]",
"byte",
",",
"t1",
"time",
".",
"Duration",
",",
"t2",
"time",
".",
"Duration",
",",
"options",
"dhcp6",
".",
"Options",
")",
"*",
"IAPD",
"{",
"if",
"options",
"==",
"nil",
"{",
"options",
"=",
"make"... | // NewIAPD creates a new IAPD from an IAID, T1 and T2 durations, and an
// Options map. If an Options map is not specified, a new one will be
// allocated. | [
"NewIAPD",
"creates",
"a",
"new",
"IAPD",
"from",
"an",
"IAID",
"T1",
"and",
"T2",
"durations",
"and",
"an",
"Options",
"map",
".",
"If",
"an",
"Options",
"map",
"is",
"not",
"specified",
"a",
"new",
"one",
"will",
"be",
"allocated",
"."
] | 2a67805d7d0b0bad6c1103058981afdea583b459 | https://github.com/mdlayher/dhcp6/blob/2a67805d7d0b0bad6c1103058981afdea583b459/dhcp6opts/iapd.go#L39-L50 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.