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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
10,000 | 256dpi/gomqtt | client/client.go | processSuback | func (c *Client) processSuback(suback *packet.Suback) error {
// remove packet from store
err := c.Session.DeletePacket(session.Outgoing, suback.ID)
if err != nil {
return err
}
// get future
subscribeFuture := c.futureStore.Get(suback.ID)
if subscribeFuture == nil {
return nil // ignore a wrongly sent Suba... | go | func (c *Client) processSuback(suback *packet.Suback) error {
// remove packet from store
err := c.Session.DeletePacket(session.Outgoing, suback.ID)
if err != nil {
return err
}
// get future
subscribeFuture := c.futureStore.Get(suback.ID)
if subscribeFuture == nil {
return nil // ignore a wrongly sent Suba... | [
"func",
"(",
"c",
"*",
"Client",
")",
"processSuback",
"(",
"suback",
"*",
"packet",
".",
"Suback",
")",
"error",
"{",
"// remove packet from store",
"err",
":=",
"c",
".",
"Session",
".",
"DeletePacket",
"(",
"session",
".",
"Outgoing",
",",
"suback",
"."... | // handle an incoming Suback packet | [
"handle",
"an",
"incoming",
"Suback",
"packet"
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/client/client.go#L559-L590 |
10,001 | 256dpi/gomqtt | client/client.go | processUnsuback | func (c *Client) processUnsuback(unsuback *packet.Unsuback) error {
// remove packet from store
err := c.Session.DeletePacket(session.Outgoing, unsuback.ID)
if err != nil {
return err
}
// get future
unsubscribeFuture := c.futureStore.Get(unsuback.ID)
if unsubscribeFuture == nil {
return nil // ignore a wro... | go | func (c *Client) processUnsuback(unsuback *packet.Unsuback) error {
// remove packet from store
err := c.Session.DeletePacket(session.Outgoing, unsuback.ID)
if err != nil {
return err
}
// get future
unsubscribeFuture := c.futureStore.Get(unsuback.ID)
if unsubscribeFuture == nil {
return nil // ignore a wro... | [
"func",
"(",
"c",
"*",
"Client",
")",
"processUnsuback",
"(",
"unsuback",
"*",
"packet",
".",
"Unsuback",
")",
"error",
"{",
"// remove packet from store",
"err",
":=",
"c",
".",
"Session",
".",
"DeletePacket",
"(",
"session",
".",
"Outgoing",
",",
"unsuback... | // handle an incoming Unsuback packet | [
"handle",
"an",
"incoming",
"Unsuback",
"packet"
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/client/client.go#L593-L613 |
10,002 | 256dpi/gomqtt | client/client.go | processPublish | func (c *Client) processPublish(publish *packet.Publish) error {
// call callback for unacknowledged and directly acknowledged messages
if publish.Message.QOS <= 1 {
if c.Callback != nil {
err := c.Callback(&publish.Message, nil)
if err != nil {
return c.die(err, true, true)
}
}
}
// handle qos 1 ... | go | func (c *Client) processPublish(publish *packet.Publish) error {
// call callback for unacknowledged and directly acknowledged messages
if publish.Message.QOS <= 1 {
if c.Callback != nil {
err := c.Callback(&publish.Message, nil)
if err != nil {
return c.die(err, true, true)
}
}
}
// handle qos 1 ... | [
"func",
"(",
"c",
"*",
"Client",
")",
"processPublish",
"(",
"publish",
"*",
"packet",
".",
"Publish",
")",
"error",
"{",
"// call callback for unacknowledged and directly acknowledged messages",
"if",
"publish",
".",
"Message",
".",
"QOS",
"<=",
"1",
"{",
"if",
... | // handle an incoming Publish packet | [
"handle",
"an",
"incoming",
"Publish",
"packet"
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/client/client.go#L616-L660 |
10,003 | 256dpi/gomqtt | client/client.go | processPubackAndPubcomp | func (c *Client) processPubackAndPubcomp(id packet.ID) error {
// remove packet from store
err := c.Session.DeletePacket(session.Outgoing, id)
if err != nil {
return err
}
// get future
publishFuture := c.futureStore.Get(id)
if publishFuture == nil {
return nil // ignore a wrongly sent Puback or Pubcomp pac... | go | func (c *Client) processPubackAndPubcomp(id packet.ID) error {
// remove packet from store
err := c.Session.DeletePacket(session.Outgoing, id)
if err != nil {
return err
}
// get future
publishFuture := c.futureStore.Get(id)
if publishFuture == nil {
return nil // ignore a wrongly sent Puback or Pubcomp pac... | [
"func",
"(",
"c",
"*",
"Client",
")",
"processPubackAndPubcomp",
"(",
"id",
"packet",
".",
"ID",
")",
"error",
"{",
"// remove packet from store",
"err",
":=",
"c",
".",
"Session",
".",
"DeletePacket",
"(",
"session",
".",
"Outgoing",
",",
"id",
")",
"\n",... | // handle an incoming Puback or Pubcomp packet | [
"handle",
"an",
"incoming",
"Puback",
"or",
"Pubcomp",
"packet"
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/client/client.go#L663-L683 |
10,004 | 256dpi/gomqtt | client/client.go | processPubrec | func (c *Client) processPubrec(id packet.ID) error {
// prepare pubrel packet
pubrel := packet.NewPubrel()
pubrel.ID = id
// overwrite stored Publish with the Pubrel packet
err := c.Session.SavePacket(session.Outgoing, pubrel)
if err != nil {
return c.die(err, true, false)
}
// send packet
err = c.send(pub... | go | func (c *Client) processPubrec(id packet.ID) error {
// prepare pubrel packet
pubrel := packet.NewPubrel()
pubrel.ID = id
// overwrite stored Publish with the Pubrel packet
err := c.Session.SavePacket(session.Outgoing, pubrel)
if err != nil {
return c.die(err, true, false)
}
// send packet
err = c.send(pub... | [
"func",
"(",
"c",
"*",
"Client",
")",
"processPubrec",
"(",
"id",
"packet",
".",
"ID",
")",
"error",
"{",
"// prepare pubrel packet",
"pubrel",
":=",
"packet",
".",
"NewPubrel",
"(",
")",
"\n",
"pubrel",
".",
"ID",
"=",
"id",
"\n\n",
"// overwrite stored P... | // handle an incoming Pubrec packet | [
"handle",
"an",
"incoming",
"Pubrec",
"packet"
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/client/client.go#L686-L704 |
10,005 | 256dpi/gomqtt | client/client.go | processPubrel | func (c *Client) processPubrel(id packet.ID) error {
// get packet from store
pkt, err := c.Session.LookupPacket(session.Incoming, id)
if err != nil {
return c.die(err, true, false)
}
// get packet from store
publish, ok := pkt.(*packet.Publish)
if !ok {
return nil // ignore a wrongly sent Pubrel packet
}
... | go | func (c *Client) processPubrel(id packet.ID) error {
// get packet from store
pkt, err := c.Session.LookupPacket(session.Incoming, id)
if err != nil {
return c.die(err, true, false)
}
// get packet from store
publish, ok := pkt.(*packet.Publish)
if !ok {
return nil // ignore a wrongly sent Pubrel packet
}
... | [
"func",
"(",
"c",
"*",
"Client",
")",
"processPubrel",
"(",
"id",
"packet",
".",
"ID",
")",
"error",
"{",
"// get packet from store",
"pkt",
",",
"err",
":=",
"c",
".",
"Session",
".",
"LookupPacket",
"(",
"session",
".",
"Incoming",
",",
"id",
")",
"\... | // handle an incoming Pubrel packet | [
"handle",
"an",
"incoming",
"Pubrel",
"packet"
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/client/client.go#L707-L745 |
10,006 | 256dpi/gomqtt | client/client.go | die | func (c *Client) die(err error, close bool, fromCallback bool) error {
c.finish.Do(func() {
err = c.cleanup(err, close, false)
if c.Callback != nil && !fromCallback {
returnedErr := c.Callback(nil, err)
if returnedErr == nil {
err = nil
}
}
})
return err
} | go | func (c *Client) die(err error, close bool, fromCallback bool) error {
c.finish.Do(func() {
err = c.cleanup(err, close, false)
if c.Callback != nil && !fromCallback {
returnedErr := c.Callback(nil, err)
if returnedErr == nil {
err = nil
}
}
})
return err
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"die",
"(",
"err",
"error",
",",
"close",
"bool",
",",
"fromCallback",
"bool",
")",
"error",
"{",
"c",
".",
"finish",
".",
"Do",
"(",
"func",
"(",
")",
"{",
"err",
"=",
"c",
".",
"cleanup",
"(",
"err",
",",... | // used for closing and cleaning up from internal goroutines | [
"used",
"for",
"closing",
"and",
"cleaning",
"up",
"from",
"internal",
"goroutines"
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/client/client.go#L840-L853 |
10,007 | 256dpi/gomqtt | client/client.go | end | func (c *Client) end(err error, possiblyClosed bool) error {
// close connection
err = c.cleanup(err, true, true)
// shutdown goroutines
c.tomb.Kill(nil)
// wait for all goroutines to exit
// goroutines will send eventual errors through the callback
c.tomb.Wait()
// do cleanup
return err
} | go | func (c *Client) end(err error, possiblyClosed bool) error {
// close connection
err = c.cleanup(err, true, true)
// shutdown goroutines
c.tomb.Kill(nil)
// wait for all goroutines to exit
// goroutines will send eventual errors through the callback
c.tomb.Wait()
// do cleanup
return err
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"end",
"(",
"err",
"error",
",",
"possiblyClosed",
"bool",
")",
"error",
"{",
"// close connection",
"err",
"=",
"c",
".",
"cleanup",
"(",
"err",
",",
"true",
",",
"true",
")",
"\n\n",
"// shutdown goroutines",
"c",
... | // called by Disconnect and Close | [
"called",
"by",
"Disconnect",
"and",
"Close"
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/client/client.go#L856-L869 |
10,008 | 256dpi/gomqtt | broker/backend.go | NewMemoryBackend | func NewMemoryBackend() *MemoryBackend {
return &MemoryBackend{
SessionQueueSize: 100,
KillTimeout: 5 * time.Second,
activeClients: make(map[string]*Client),
storedSessions: make(map[string]*memorySession),
temporarySessions: make(map[*Client]*memorySession),
retainedMessages: topic.NewTree(... | go | func NewMemoryBackend() *MemoryBackend {
return &MemoryBackend{
SessionQueueSize: 100,
KillTimeout: 5 * time.Second,
activeClients: make(map[string]*Client),
storedSessions: make(map[string]*memorySession),
temporarySessions: make(map[*Client]*memorySession),
retainedMessages: topic.NewTree(... | [
"func",
"NewMemoryBackend",
"(",
")",
"*",
"MemoryBackend",
"{",
"return",
"&",
"MemoryBackend",
"{",
"SessionQueueSize",
":",
"100",
",",
"KillTimeout",
":",
"5",
"*",
"time",
".",
"Second",
",",
"activeClients",
":",
"make",
"(",
"map",
"[",
"string",
"]... | // NewMemoryBackend returns a new MemoryBackend. | [
"NewMemoryBackend",
"returns",
"a",
"new",
"MemoryBackend",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/broker/backend.go#L109-L118 |
10,009 | 256dpi/gomqtt | broker/backend.go | Authenticate | func (m *MemoryBackend) Authenticate(client *Client, user, password string) (bool, error) {
// acquire global mutex
m.globalMutex.Lock()
defer m.globalMutex.Unlock()
// return error if closing
if m.closing {
return false, ErrClosing
}
// allow all if there are no credentials
if m.Credentials == nil {
retu... | go | func (m *MemoryBackend) Authenticate(client *Client, user, password string) (bool, error) {
// acquire global mutex
m.globalMutex.Lock()
defer m.globalMutex.Unlock()
// return error if closing
if m.closing {
return false, ErrClosing
}
// allow all if there are no credentials
if m.Credentials == nil {
retu... | [
"func",
"(",
"m",
"*",
"MemoryBackend",
")",
"Authenticate",
"(",
"client",
"*",
"Client",
",",
"user",
",",
"password",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"// acquire global mutex",
"m",
".",
"globalMutex",
".",
"Lock",
"(",
")",
"\n",
... | // Authenticate will authenticates a clients credentials. | [
"Authenticate",
"will",
"authenticates",
"a",
"clients",
"credentials",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/broker/backend.go#L121-L142 |
10,010 | 256dpi/gomqtt | broker/backend.go | Setup | func (m *MemoryBackend) Setup(client *Client, id string, clean bool) (Session, bool, error) {
// acquire setup mutex
m.setupMutex.Lock()
defer m.setupMutex.Unlock()
// acquire global mutex
m.globalMutex.Lock()
defer m.globalMutex.Unlock()
// return error if closing
if m.closing {
return nil, false, ErrClosi... | go | func (m *MemoryBackend) Setup(client *Client, id string, clean bool) (Session, bool, error) {
// acquire setup mutex
m.setupMutex.Lock()
defer m.setupMutex.Unlock()
// acquire global mutex
m.globalMutex.Lock()
defer m.globalMutex.Unlock()
// return error if closing
if m.closing {
return nil, false, ErrClosi... | [
"func",
"(",
"m",
"*",
"MemoryBackend",
")",
"Setup",
"(",
"client",
"*",
"Client",
",",
"id",
"string",
",",
"clean",
"bool",
")",
"(",
"Session",
",",
"bool",
",",
"error",
")",
"{",
"// acquire setup mutex",
"m",
".",
"setupMutex",
".",
"Lock",
"(",... | // Setup will close existing clients and return an appropriate session. | [
"Setup",
"will",
"close",
"existing",
"clients",
"and",
"return",
"an",
"appropriate",
"session",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/broker/backend.go#L145-L258 |
10,011 | 256dpi/gomqtt | broker/backend.go | Subscribe | func (m *MemoryBackend) Subscribe(client *Client, subs []packet.Subscription, ack Ack) error {
// acquire global mutex
m.globalMutex.Lock()
defer m.globalMutex.Unlock()
// save subscription
for _, sub := range subs {
client.Session().(*memorySession).subscriptions.Set(sub.Topic, sub)
}
// call ack if provide... | go | func (m *MemoryBackend) Subscribe(client *Client, subs []packet.Subscription, ack Ack) error {
// acquire global mutex
m.globalMutex.Lock()
defer m.globalMutex.Unlock()
// save subscription
for _, sub := range subs {
client.Session().(*memorySession).subscriptions.Set(sub.Topic, sub)
}
// call ack if provide... | [
"func",
"(",
"m",
"*",
"MemoryBackend",
")",
"Subscribe",
"(",
"client",
"*",
"Client",
",",
"subs",
"[",
"]",
"packet",
".",
"Subscription",
",",
"ack",
"Ack",
")",
"error",
"{",
"// acquire global mutex",
"m",
".",
"globalMutex",
".",
"Lock",
"(",
")",... | // Subscribe will store the subscription and queue retained messages. | [
"Subscribe",
"will",
"store",
"the",
"subscription",
"and",
"queue",
"retained",
"messages",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/broker/backend.go#L266-L301 |
10,012 | 256dpi/gomqtt | broker/backend.go | Unsubscribe | func (m *MemoryBackend) Unsubscribe(client *Client, topics []string, ack Ack) error {
// delete subscriptions
for _, t := range topics {
client.Session().(*memorySession).subscriptions.Empty(t)
}
// call ack if provided
if ack != nil {
ack()
}
return nil
} | go | func (m *MemoryBackend) Unsubscribe(client *Client, topics []string, ack Ack) error {
// delete subscriptions
for _, t := range topics {
client.Session().(*memorySession).subscriptions.Empty(t)
}
// call ack if provided
if ack != nil {
ack()
}
return nil
} | [
"func",
"(",
"m",
"*",
"MemoryBackend",
")",
"Unsubscribe",
"(",
"client",
"*",
"Client",
",",
"topics",
"[",
"]",
"string",
",",
"ack",
"Ack",
")",
"error",
"{",
"// delete subscriptions",
"for",
"_",
",",
"t",
":=",
"range",
"topics",
"{",
"client",
... | // Unsubscribe will delete the subscription. | [
"Unsubscribe",
"will",
"delete",
"the",
"subscription",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/broker/backend.go#L304-L316 |
10,013 | 256dpi/gomqtt | broker/backend.go | Publish | func (m *MemoryBackend) Publish(client *Client, msg *packet.Message, ack Ack) error {
// acquire global mutex
m.globalMutex.Lock()
defer m.globalMutex.Unlock()
// this implementation is very basic and will block the backend on every
// publish. clients that stay connected but won't drain their queue will
// even... | go | func (m *MemoryBackend) Publish(client *Client, msg *packet.Message, ack Ack) error {
// acquire global mutex
m.globalMutex.Lock()
defer m.globalMutex.Unlock()
// this implementation is very basic and will block the backend on every
// publish. clients that stay connected but won't drain their queue will
// even... | [
"func",
"(",
"m",
"*",
"MemoryBackend",
")",
"Publish",
"(",
"client",
"*",
"Client",
",",
"msg",
"*",
"packet",
".",
"Message",
",",
"ack",
"Ack",
")",
"error",
"{",
"// acquire global mutex",
"m",
".",
"globalMutex",
".",
"Lock",
"(",
")",
"\n",
"def... | // Publish will handle retained messages and add the message to the session queues. | [
"Publish",
"will",
"handle",
"retained",
"messages",
"and",
"add",
"the",
"message",
"to",
"the",
"session",
"queues",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/broker/backend.go#L319-L408 |
10,014 | 256dpi/gomqtt | broker/backend.go | Dequeue | func (m *MemoryBackend) Dequeue(client *Client) (*packet.Message, Ack, error) {
// mutex locking not needed
// get session
sess := client.Session().(*memorySession)
// this implementation is very basic and will dequeue messages immediately
// and not return no ack. messages are lost if the client fails to handle... | go | func (m *MemoryBackend) Dequeue(client *Client) (*packet.Message, Ack, error) {
// mutex locking not needed
// get session
sess := client.Session().(*memorySession)
// this implementation is very basic and will dequeue messages immediately
// and not return no ack. messages are lost if the client fails to handle... | [
"func",
"(",
"m",
"*",
"MemoryBackend",
")",
"Dequeue",
"(",
"client",
"*",
"Client",
")",
"(",
"*",
"packet",
".",
"Message",
",",
"Ack",
",",
"error",
")",
"{",
"// mutex locking not needed",
"// get session",
"sess",
":=",
"client",
".",
"Session",
"(",... | // Dequeue will get the next message from the temporary or stored queue. | [
"Dequeue",
"will",
"get",
"the",
"next",
"message",
"from",
"the",
"temporary",
"or",
"stored",
"queue",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/broker/backend.go#L411-L429 |
10,015 | 256dpi/gomqtt | broker/backend.go | Terminate | func (m *MemoryBackend) Terminate(client *Client) error {
// acquire global mutex
m.globalMutex.Lock()
defer m.globalMutex.Unlock()
// release session if available
sess, ok := client.Session().(*memorySession)
if ok && sess != nil {
sess.owner = nil
}
// remove any temporary session
delete(m.temporarySessi... | go | func (m *MemoryBackend) Terminate(client *Client) error {
// acquire global mutex
m.globalMutex.Lock()
defer m.globalMutex.Unlock()
// release session if available
sess, ok := client.Session().(*memorySession)
if ok && sess != nil {
sess.owner = nil
}
// remove any temporary session
delete(m.temporarySessi... | [
"func",
"(",
"m",
"*",
"MemoryBackend",
")",
"Terminate",
"(",
"client",
"*",
"Client",
")",
"error",
"{",
"// acquire global mutex",
"m",
".",
"globalMutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"m",
".",
"globalMutex",
".",
"Unlock",
"(",
")",
"\n\n",... | // Terminate will disassociate the session from the client. | [
"Terminate",
"will",
"disassociate",
"the",
"session",
"from",
"the",
"client",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/broker/backend.go#L432-L450 |
10,016 | 256dpi/gomqtt | broker/backend.go | Log | func (m *MemoryBackend) Log(event LogEvent, client *Client, pkt packet.Generic, msg *packet.Message, err error) {
// call logger if available
if m.Logger != nil {
m.Logger(event, client, pkt, msg, err)
}
} | go | func (m *MemoryBackend) Log(event LogEvent, client *Client, pkt packet.Generic, msg *packet.Message, err error) {
// call logger if available
if m.Logger != nil {
m.Logger(event, client, pkt, msg, err)
}
} | [
"func",
"(",
"m",
"*",
"MemoryBackend",
")",
"Log",
"(",
"event",
"LogEvent",
",",
"client",
"*",
"Client",
",",
"pkt",
"packet",
".",
"Generic",
",",
"msg",
"*",
"packet",
".",
"Message",
",",
"err",
"error",
")",
"{",
"// call logger if available",
"if... | // Log will call the associated logger. | [
"Log",
"will",
"call",
"the",
"associated",
"logger",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/broker/backend.go#L453-L458 |
10,017 | 256dpi/gomqtt | broker/backend.go | Close | func (m *MemoryBackend) Close(timeout time.Duration) bool {
// acquire global mutex
m.globalMutex.Lock()
// set closing
m.closing = true
// prepare list
var clients []*Client
// close temporary sessions
for _, sess := range m.temporarySessions {
sess.owner.Close()
clients = append(clients, sess.owner)
}... | go | func (m *MemoryBackend) Close(timeout time.Duration) bool {
// acquire global mutex
m.globalMutex.Lock()
// set closing
m.closing = true
// prepare list
var clients []*Client
// close temporary sessions
for _, sess := range m.temporarySessions {
sess.owner.Close()
clients = append(clients, sess.owner)
}... | [
"func",
"(",
"m",
"*",
"MemoryBackend",
")",
"Close",
"(",
"timeout",
"time",
".",
"Duration",
")",
"bool",
"{",
"// acquire global mutex",
"m",
".",
"globalMutex",
".",
"Lock",
"(",
")",
"\n\n",
"// set closing",
"m",
".",
"closing",
"=",
"true",
"\n\n",
... | // Close will close all active clients and close the backend. The return value
// denotes if the timeout has been reached. | [
"Close",
"will",
"close",
"all",
"active",
"clients",
"and",
"close",
"the",
"backend",
".",
"The",
"return",
"value",
"denotes",
"if",
"the",
"timeout",
"has",
"been",
"reached",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/broker/backend.go#L462-L508 |
10,018 | 256dpi/gomqtt | client/config.go | NewConfig | func NewConfig(url string) *Config {
return &Config{
BrokerURL: url,
CleanSession: true,
KeepAlive: "30s",
ValidateSubs: true,
}
} | go | func NewConfig(url string) *Config {
return &Config{
BrokerURL: url,
CleanSession: true,
KeepAlive: "30s",
ValidateSubs: true,
}
} | [
"func",
"NewConfig",
"(",
"url",
"string",
")",
"*",
"Config",
"{",
"return",
"&",
"Config",
"{",
"BrokerURL",
":",
"url",
",",
"CleanSession",
":",
"true",
",",
"KeepAlive",
":",
"\"",
"\"",
",",
"ValidateSubs",
":",
"true",
",",
"}",
"\n",
"}"
] | // NewConfig creates a new Config using the specified URL. | [
"NewConfig",
"creates",
"a",
"new",
"Config",
"using",
"the",
"specified",
"URL",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/client/config.go#L44-L51 |
10,019 | 256dpi/gomqtt | client/config.go | NewConfigWithClientID | func NewConfigWithClientID(url, id string) *Config {
config := NewConfig(url)
config.ClientID = id
return config
} | go | func NewConfigWithClientID(url, id string) *Config {
config := NewConfig(url)
config.ClientID = id
return config
} | [
"func",
"NewConfigWithClientID",
"(",
"url",
",",
"id",
"string",
")",
"*",
"Config",
"{",
"config",
":=",
"NewConfig",
"(",
"url",
")",
"\n",
"config",
".",
"ClientID",
"=",
"id",
"\n",
"return",
"config",
"\n",
"}"
] | // NewConfigWithClientID creates a new Config using the specified URL and client ID. | [
"NewConfigWithClientID",
"creates",
"a",
"new",
"Config",
"using",
"the",
"specified",
"URL",
"and",
"client",
"ID",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/client/config.go#L54-L58 |
10,020 | 256dpi/gomqtt | transport/dialer.go | NewDialer | func NewDialer() *Dialer {
return &Dialer{
DefaultTCPPort: "1883",
DefaultTLSPort: "8883",
DefaultWSPort: "80",
DefaultWSSPort: "443",
webSocketDialer: &websocket.Dialer{
Proxy: http.ProxyFromEnvironment,
Subprotocols: []string{"mqtt"},
},
}
} | go | func NewDialer() *Dialer {
return &Dialer{
DefaultTCPPort: "1883",
DefaultTLSPort: "8883",
DefaultWSPort: "80",
DefaultWSSPort: "443",
webSocketDialer: &websocket.Dialer{
Proxy: http.ProxyFromEnvironment,
Subprotocols: []string{"mqtt"},
},
}
} | [
"func",
"NewDialer",
"(",
")",
"*",
"Dialer",
"{",
"return",
"&",
"Dialer",
"{",
"DefaultTCPPort",
":",
"\"",
"\"",
",",
"DefaultTLSPort",
":",
"\"",
"\"",
",",
"DefaultWSPort",
":",
"\"",
"\"",
",",
"DefaultWSSPort",
":",
"\"",
"\"",
",",
"webSocketDial... | // NewDialer returns a new Dialer. | [
"NewDialer",
"returns",
"a",
"new",
"Dialer",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/transport/dialer.go#L29-L40 |
10,021 | 256dpi/gomqtt | transport/dialer.go | Dial | func (d *Dialer) Dial(urlString string) (Conn, error) {
// ensure write delay default
if d.MaxWriteDelay == 0 {
d.MaxWriteDelay = 10 * time.Millisecond
}
urlParts, err := url.ParseRequestURI(urlString)
if err != nil {
return nil, err
}
host, port, err := net.SplitHostPort(urlParts.Host)
if err != nil {
... | go | func (d *Dialer) Dial(urlString string) (Conn, error) {
// ensure write delay default
if d.MaxWriteDelay == 0 {
d.MaxWriteDelay = 10 * time.Millisecond
}
urlParts, err := url.ParseRequestURI(urlString)
if err != nil {
return nil, err
}
host, port, err := net.SplitHostPort(urlParts.Host)
if err != nil {
... | [
"func",
"(",
"d",
"*",
"Dialer",
")",
"Dial",
"(",
"urlString",
"string",
")",
"(",
"Conn",
",",
"error",
")",
"{",
"// ensure write delay default",
"if",
"d",
".",
"MaxWriteDelay",
"==",
"0",
"{",
"d",
".",
"MaxWriteDelay",
"=",
"10",
"*",
"time",
"."... | // Dial initiates a connection based in information extracted from an URL. | [
"Dial",
"initiates",
"a",
"connection",
"based",
"in",
"information",
"extracted",
"from",
"an",
"URL",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/transport/dialer.go#L54-L124 |
10,022 | 256dpi/gomqtt | packet/identified.go | identifiedDecode | func identifiedDecode(src []byte, t Type) (int, ID, error) {
total := 0
// decode header
hl, _, rl, err := headerDecode(src, t)
total += hl
if err != nil {
return total, 0, err
}
// check remaining length
if rl != 2 {
return total, 0, makeError(t, "expected remaining length to be 2")
}
// read packet i... | go | func identifiedDecode(src []byte, t Type) (int, ID, error) {
total := 0
// decode header
hl, _, rl, err := headerDecode(src, t)
total += hl
if err != nil {
return total, 0, err
}
// check remaining length
if rl != 2 {
return total, 0, makeError(t, "expected remaining length to be 2")
}
// read packet i... | [
"func",
"identifiedDecode",
"(",
"src",
"[",
"]",
"byte",
",",
"t",
"Type",
")",
"(",
"int",
",",
"ID",
",",
"error",
")",
"{",
"total",
":=",
"0",
"\n\n",
"// decode header",
"hl",
",",
"_",
",",
"rl",
",",
"err",
":=",
"headerDecode",
"(",
"src",... | // decodes an identified packet | [
"decodes",
"an",
"identified",
"packet"
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/packet/identified.go#L14-L39 |
10,023 | 256dpi/gomqtt | packet/identified.go | identifiedEncode | func identifiedEncode(dst []byte, id ID, t Type) (int, error) {
total := 0
// check packet id
if !id.Valid() {
return total, makeError(t, "packet id must be grater than zero")
}
// encode header
n, err := headerEncode(dst[total:], 0, 2, identifiedLen(), t)
total += n
if err != nil {
return total, err
}
... | go | func identifiedEncode(dst []byte, id ID, t Type) (int, error) {
total := 0
// check packet id
if !id.Valid() {
return total, makeError(t, "packet id must be grater than zero")
}
// encode header
n, err := headerEncode(dst[total:], 0, 2, identifiedLen(), t)
total += n
if err != nil {
return total, err
}
... | [
"func",
"identifiedEncode",
"(",
"dst",
"[",
"]",
"byte",
",",
"id",
"ID",
",",
"t",
"Type",
")",
"(",
"int",
",",
"error",
")",
"{",
"total",
":=",
"0",
"\n\n",
"// check packet id",
"if",
"!",
"id",
".",
"Valid",
"(",
")",
"{",
"return",
"total",... | // encodes an identified packet | [
"encodes",
"an",
"identified",
"packet"
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/packet/identified.go#L42-L62 |
10,024 | 256dpi/gomqtt | broker/engine.go | NewEngine | func NewEngine(backend Backend) *Engine {
return &Engine{
Backend: backend,
ConnectTimeout: 10 * time.Second,
}
} | go | func NewEngine(backend Backend) *Engine {
return &Engine{
Backend: backend,
ConnectTimeout: 10 * time.Second,
}
} | [
"func",
"NewEngine",
"(",
"backend",
"Backend",
")",
"*",
"Engine",
"{",
"return",
"&",
"Engine",
"{",
"Backend",
":",
"backend",
",",
"ConnectTimeout",
":",
"10",
"*",
"time",
".",
"Second",
",",
"}",
"\n",
"}"
] | // NewEngine returns a new Engine. | [
"NewEngine",
"returns",
"a",
"new",
"Engine",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/broker/engine.go#L34-L39 |
10,025 | 256dpi/gomqtt | broker/engine.go | Accept | func (e *Engine) Accept(server transport.Server) {
e.tomb.Go(func() error {
for {
// return if dying
if !e.tomb.Alive() {
return tomb.ErrDying
}
// accept next connection
conn, err := server.Accept()
if err != nil {
// call error callback if available
if e.OnError != nil {
e.OnErr... | go | func (e *Engine) Accept(server transport.Server) {
e.tomb.Go(func() error {
for {
// return if dying
if !e.tomb.Alive() {
return tomb.ErrDying
}
// accept next connection
conn, err := server.Accept()
if err != nil {
// call error callback if available
if e.OnError != nil {
e.OnErr... | [
"func",
"(",
"e",
"*",
"Engine",
")",
"Accept",
"(",
"server",
"transport",
".",
"Server",
")",
"{",
"e",
".",
"tomb",
".",
"Go",
"(",
"func",
"(",
")",
"error",
"{",
"for",
"{",
"// return if dying",
"if",
"!",
"e",
".",
"tomb",
".",
"Alive",
"(... | // Accept begins accepting connections from the passed server. | [
"Accept",
"begins",
"accepting",
"connections",
"from",
"the",
"passed",
"server",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/broker/engine.go#L42-L67 |
10,026 | 256dpi/gomqtt | broker/engine.go | Handle | func (e *Engine) Handle(conn transport.Conn) bool {
// check conn
if conn == nil {
panic("passed conn is nil")
}
// acquire mutex
e.mutex.Lock()
defer e.mutex.Unlock()
// close conn immediately when dying
if !e.tomb.Alive() {
_ = conn.Close()
return false
}
// set default read limit
conn.SetReadLimi... | go | func (e *Engine) Handle(conn transport.Conn) bool {
// check conn
if conn == nil {
panic("passed conn is nil")
}
// acquire mutex
e.mutex.Lock()
defer e.mutex.Unlock()
// close conn immediately when dying
if !e.tomb.Alive() {
_ = conn.Close()
return false
}
// set default read limit
conn.SetReadLimi... | [
"func",
"(",
"e",
"*",
"Engine",
")",
"Handle",
"(",
"conn",
"transport",
".",
"Conn",
")",
"bool",
"{",
"// check conn",
"if",
"conn",
"==",
"nil",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// acquire mutex",
"e",
".",
"mutex",
".",
... | // Handle takes over responsibility and handles a transport.Conn. It returns
// false if the engine is closing and the connection has been closed. | [
"Handle",
"takes",
"over",
"responsibility",
"and",
"handles",
"a",
"transport",
".",
"Conn",
".",
"It",
"returns",
"false",
"if",
"the",
"engine",
"is",
"closing",
"and",
"the",
"connection",
"has",
"been",
"closed",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/broker/engine.go#L71-L97 |
10,027 | 256dpi/gomqtt | broker/engine.go | Run | func Run(engine *Engine, protocol string) (string, chan struct{}, chan struct{}) {
// launch server
server, err := transport.Launch(protocol + "://localhost:0")
if err != nil {
panic(err)
}
// prepare channels
quit := make(chan struct{})
done := make(chan struct{})
// start accepting connections
engine.Acc... | go | func Run(engine *Engine, protocol string) (string, chan struct{}, chan struct{}) {
// launch server
server, err := transport.Launch(protocol + "://localhost:0")
if err != nil {
panic(err)
}
// prepare channels
quit := make(chan struct{})
done := make(chan struct{})
// start accepting connections
engine.Acc... | [
"func",
"Run",
"(",
"engine",
"*",
"Engine",
",",
"protocol",
"string",
")",
"(",
"string",
",",
"chan",
"struct",
"{",
"}",
",",
"chan",
"struct",
"{",
"}",
")",
"{",
"// launch server",
"server",
",",
"err",
":=",
"transport",
".",
"Launch",
"(",
"... | // Run runs the passed engine on a random available port and returns a channel
// that can be closed to shutdown the engine. This method is intended to be used
// in testing scenarios. | [
"Run",
"runs",
"the",
"passed",
"engine",
"on",
"a",
"random",
"available",
"port",
"and",
"returns",
"a",
"channel",
"that",
"can",
"be",
"closed",
"to",
"shutdown",
"the",
"engine",
".",
"This",
"method",
"is",
"intended",
"to",
"be",
"used",
"in",
"te... | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/broker/engine.go#L116-L148 |
10,028 | 256dpi/gomqtt | packet/strings.go | readLPBytes | func readLPBytes(buf []byte, safe bool, t Type) ([]byte, int, error) {
if len(buf) < 2 {
return nil, 0, makeError(t, "insufficient buffer size, expected 2, got %d", len(buf))
}
n, total := 0, 0
n = int(binary.BigEndian.Uint16(buf))
total += 2
total += n
if len(buf) < total {
return nil, total, makeError(t... | go | func readLPBytes(buf []byte, safe bool, t Type) ([]byte, int, error) {
if len(buf) < 2 {
return nil, 0, makeError(t, "insufficient buffer size, expected 2, got %d", len(buf))
}
n, total := 0, 0
n = int(binary.BigEndian.Uint16(buf))
total += 2
total += n
if len(buf) < total {
return nil, total, makeError(t... | [
"func",
"readLPBytes",
"(",
"buf",
"[",
"]",
"byte",
",",
"safe",
"bool",
",",
"t",
"Type",
")",
"(",
"[",
"]",
"byte",
",",
"int",
",",
"error",
")",
"{",
"if",
"len",
"(",
"buf",
")",
"<",
"2",
"{",
"return",
"nil",
",",
"0",
",",
"makeErro... | // read length prefixed bytes | [
"read",
"length",
"prefixed",
"bytes"
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/packet/strings.go#L10-L33 |
10,029 | 256dpi/gomqtt | packet/strings.go | readLPString | func readLPString(buf []byte, t Type) (string, int, error) {
if len(buf) < 2 {
return "", 0, makeError(t, "insufficient buffer size, expected 2, got %d", len(buf))
}
n, total := 0, 0
n = int(binary.BigEndian.Uint16(buf))
total += 2
total += n
if len(buf) < total {
return "", total, makeError(t, "insuffici... | go | func readLPString(buf []byte, t Type) (string, int, error) {
if len(buf) < 2 {
return "", 0, makeError(t, "insufficient buffer size, expected 2, got %d", len(buf))
}
n, total := 0, 0
n = int(binary.BigEndian.Uint16(buf))
total += 2
total += n
if len(buf) < total {
return "", total, makeError(t, "insuffici... | [
"func",
"readLPString",
"(",
"buf",
"[",
"]",
"byte",
",",
"t",
"Type",
")",
"(",
"string",
",",
"int",
",",
"error",
")",
"{",
"if",
"len",
"(",
"buf",
")",
"<",
"2",
"{",
"return",
"\"",
"\"",
",",
"0",
",",
"makeError",
"(",
"t",
",",
"\""... | // read length prefixed string | [
"read",
"length",
"prefixed",
"string"
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/packet/strings.go#L36-L52 |
10,030 | 256dpi/gomqtt | packet/strings.go | writeLPBytes | func writeLPBytes(buf []byte, b []byte, t Type) (int, error) {
total, n := 0, len(b)
if n > int(maxLPLength) {
return 0, makeError(t, "length (%d) greater than %d bytes", n, maxLPLength)
}
if len(buf) < 2+n {
return 0, makeError(t, "insufficient buffer size, expected %d, got %d", 2+n, len(buf))
}
binary.Bi... | go | func writeLPBytes(buf []byte, b []byte, t Type) (int, error) {
total, n := 0, len(b)
if n > int(maxLPLength) {
return 0, makeError(t, "length (%d) greater than %d bytes", n, maxLPLength)
}
if len(buf) < 2+n {
return 0, makeError(t, "insufficient buffer size, expected %d, got %d", 2+n, len(buf))
}
binary.Bi... | [
"func",
"writeLPBytes",
"(",
"buf",
"[",
"]",
"byte",
",",
"b",
"[",
"]",
"byte",
",",
"t",
"Type",
")",
"(",
"int",
",",
"error",
")",
"{",
"total",
",",
"n",
":=",
"0",
",",
"len",
"(",
"b",
")",
"\n\n",
"if",
"n",
">",
"int",
"(",
"maxLP... | // write length prefixed bytes | [
"write",
"length",
"prefixed",
"bytes"
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/packet/strings.go#L55-L73 |
10,031 | 256dpi/gomqtt | packet/strings.go | writeLPString | func writeLPString(buf []byte, str string, t Type) (int, error) {
return writeLPBytes(buf, []byte(str), t)
} | go | func writeLPString(buf []byte, str string, t Type) (int, error) {
return writeLPBytes(buf, []byte(str), t)
} | [
"func",
"writeLPString",
"(",
"buf",
"[",
"]",
"byte",
",",
"str",
"string",
",",
"t",
"Type",
")",
"(",
"int",
",",
"error",
")",
"{",
"return",
"writeLPBytes",
"(",
"buf",
",",
"[",
"]",
"byte",
"(",
"str",
")",
",",
"t",
")",
"\n",
"}"
] | // write length prefixed string | [
"write",
"length",
"prefixed",
"string"
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/packet/strings.go#L76-L78 |
10,032 | 256dpi/gomqtt | broker/client.go | NewClient | func NewClient(backend Backend, conn transport.Conn) *Client {
// create client
c := &Client{
state: clientConnecting,
backend: backend,
conn: conn,
done: make(chan struct{}),
}
// start processor
c.tomb.Go(c.processor)
// run cleanup goroutine
go func() {
// wait for death and cleanup
_ = ... | go | func NewClient(backend Backend, conn transport.Conn) *Client {
// create client
c := &Client{
state: clientConnecting,
backend: backend,
conn: conn,
done: make(chan struct{}),
}
// start processor
c.tomb.Go(c.processor)
// run cleanup goroutine
go func() {
// wait for death and cleanup
_ = ... | [
"func",
"NewClient",
"(",
"backend",
"Backend",
",",
"conn",
"transport",
".",
"Conn",
")",
"*",
"Client",
"{",
"// create client",
"c",
":=",
"&",
"Client",
"{",
"state",
":",
"clientConnecting",
",",
"backend",
":",
"backend",
",",
"conn",
":",
"conn",
... | // NewClient takes over a connection and returns a Client. | [
"NewClient",
"takes",
"over",
"a",
"connection",
"and",
"returns",
"a",
"Client",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/broker/client.go#L257-L280 |
10,033 | 256dpi/gomqtt | broker/client.go | Close | func (c *Client) Close() {
_ = c.conn.Close()
c.tomb.Kill(ErrClientClosed)
} | go | func (c *Client) Close() {
_ = c.conn.Close()
c.tomb.Kill(ErrClientClosed)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Close",
"(",
")",
"{",
"_",
"=",
"c",
".",
"conn",
".",
"Close",
"(",
")",
"\n",
"c",
".",
"tomb",
".",
"Kill",
"(",
"ErrClientClosed",
")",
"\n",
"}"
] | // Close will immediately close the client. | [
"Close",
"will",
"immediately",
"close",
"the",
"client",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/broker/client.go#L299-L302 |
10,034 | 256dpi/gomqtt | broker/client.go | processPacket | func (c *Client) processPacket(pkt packet.Generic) error {
// prepare error
var err error
// handle individual packets
switch typedPkt := pkt.(type) {
case *packet.Subscribe:
err = c.processSubscribe(typedPkt)
case *packet.Unsubscribe:
err = c.processUnsubscribe(typedPkt)
case *packet.Publish:
err = c.pro... | go | func (c *Client) processPacket(pkt packet.Generic) error {
// prepare error
var err error
// handle individual packets
switch typedPkt := pkt.(type) {
case *packet.Subscribe:
err = c.processSubscribe(typedPkt)
case *packet.Unsubscribe:
err = c.processUnsubscribe(typedPkt)
case *packet.Publish:
err = c.pro... | [
"func",
"(",
"c",
"*",
"Client",
")",
"processPacket",
"(",
"pkt",
"packet",
".",
"Generic",
")",
"error",
"{",
"// prepare error",
"var",
"err",
"error",
"\n\n",
"// handle individual packets",
"switch",
"typedPkt",
":=",
"pkt",
".",
"(",
"type",
")",
"{",
... | // handle an incoming Generic | [
"handle",
"an",
"incoming",
"Generic"
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/broker/client.go#L636-L670 |
10,035 | 256dpi/gomqtt | broker/client.go | processPingreq | func (c *Client) processPingreq() error {
// send a pingresp packet
err := c.send(packet.NewPingresp(), true)
if err != nil {
return c.die(TransportError, err)
}
return nil
} | go | func (c *Client) processPingreq() error {
// send a pingresp packet
err := c.send(packet.NewPingresp(), true)
if err != nil {
return c.die(TransportError, err)
}
return nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"processPingreq",
"(",
")",
"error",
"{",
"// send a pingresp packet",
"err",
":=",
"c",
".",
"send",
"(",
"packet",
".",
"NewPingresp",
"(",
")",
",",
"true",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
... | // handle an incoming Pingreq packet | [
"handle",
"an",
"incoming",
"Pingreq",
"packet"
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/broker/client.go#L673-L681 |
10,036 | 256dpi/gomqtt | broker/client.go | processSubscribe | func (c *Client) processSubscribe(pkt *packet.Subscribe) error {
// acquire subscribe token
select {
case <-c.subscribeTokens:
// continue
case <-time.After(c.TokenTimeout):
return c.die(ClientError, ErrTokenTimeout)
case <-c.tomb.Dying():
return tomb.ErrDying
}
// prepare suback packet
suback := packet.... | go | func (c *Client) processSubscribe(pkt *packet.Subscribe) error {
// acquire subscribe token
select {
case <-c.subscribeTokens:
// continue
case <-time.After(c.TokenTimeout):
return c.die(ClientError, ErrTokenTimeout)
case <-c.tomb.Dying():
return tomb.ErrDying
}
// prepare suback packet
suback := packet.... | [
"func",
"(",
"c",
"*",
"Client",
")",
"processSubscribe",
"(",
"pkt",
"*",
"packet",
".",
"Subscribe",
")",
"error",
"{",
"// acquire subscribe token",
"select",
"{",
"case",
"<-",
"c",
".",
"subscribeTokens",
":",
"// continue",
"case",
"<-",
"time",
".",
... | // handle an incoming subscribe packet | [
"handle",
"an",
"incoming",
"subscribe",
"packet"
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/broker/client.go#L684-L717 |
10,037 | 256dpi/gomqtt | broker/client.go | processUnsubscribe | func (c *Client) processUnsubscribe(pkt *packet.Unsubscribe) error {
// acquire subscribe token
select {
case <-c.subscribeTokens:
// continue
case <-time.After(c.TokenTimeout):
return c.die(ClientError, ErrTokenTimeout)
case <-c.tomb.Dying():
return tomb.ErrDying
}
// prepare unsuback packet
unsuback :=... | go | func (c *Client) processUnsubscribe(pkt *packet.Unsubscribe) error {
// acquire subscribe token
select {
case <-c.subscribeTokens:
// continue
case <-time.After(c.TokenTimeout):
return c.die(ClientError, ErrTokenTimeout)
case <-c.tomb.Dying():
return tomb.ErrDying
}
// prepare unsuback packet
unsuback :=... | [
"func",
"(",
"c",
"*",
"Client",
")",
"processUnsubscribe",
"(",
"pkt",
"*",
"packet",
".",
"Unsubscribe",
")",
"error",
"{",
"// acquire subscribe token",
"select",
"{",
"case",
"<-",
"c",
".",
"subscribeTokens",
":",
"// continue",
"case",
"<-",
"time",
".... | // handle an incoming unsubscribe packet | [
"handle",
"an",
"incoming",
"unsubscribe",
"packet"
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/broker/client.go#L720-L747 |
10,038 | 256dpi/gomqtt | broker/client.go | processPublish | func (c *Client) processPublish(publish *packet.Publish) error {
// handle qos 0 flow
if publish.Message.QOS == 0 {
// publish message
err := c.backend.Publish(c, &publish.Message, nil)
if err != nil {
return c.die(BackendError, err)
}
c.backend.Log(MessagePublished, c, nil, &publish.Message, nil)
re... | go | func (c *Client) processPublish(publish *packet.Publish) error {
// handle qos 0 flow
if publish.Message.QOS == 0 {
// publish message
err := c.backend.Publish(c, &publish.Message, nil)
if err != nil {
return c.die(BackendError, err)
}
c.backend.Log(MessagePublished, c, nil, &publish.Message, nil)
re... | [
"func",
"(",
"c",
"*",
"Client",
")",
"processPublish",
"(",
"publish",
"*",
"packet",
".",
"Publish",
")",
"error",
"{",
"// handle qos 0 flow",
"if",
"publish",
".",
"Message",
".",
"QOS",
"==",
"0",
"{",
"// publish message",
"err",
":=",
"c",
".",
"b... | // handle an incoming publish packet | [
"handle",
"an",
"incoming",
"publish",
"packet"
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/broker/client.go#L750-L816 |
10,039 | 256dpi/gomqtt | broker/client.go | processPubackAndPubcomp | func (c *Client) processPubackAndPubcomp(id packet.ID) error {
// remove packet from store
err := c.session.DeletePacket(session.Outgoing, id)
if err != nil {
return c.die(SessionError, err)
}
// put back dequeue token
select {
case c.dequeueTokens <- struct{}{}:
default:
// continue if full for some reaso... | go | func (c *Client) processPubackAndPubcomp(id packet.ID) error {
// remove packet from store
err := c.session.DeletePacket(session.Outgoing, id)
if err != nil {
return c.die(SessionError, err)
}
// put back dequeue token
select {
case c.dequeueTokens <- struct{}{}:
default:
// continue if full for some reaso... | [
"func",
"(",
"c",
"*",
"Client",
")",
"processPubackAndPubcomp",
"(",
"id",
"packet",
".",
"ID",
")",
"error",
"{",
"// remove packet from store",
"err",
":=",
"c",
".",
"session",
".",
"DeletePacket",
"(",
"session",
".",
"Outgoing",
",",
"id",
")",
"\n",... | // handle an incoming p or pubcomp packet | [
"handle",
"an",
"incoming",
"p",
"or",
"pubcomp",
"packet"
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/broker/client.go#L819-L834 |
10,040 | 256dpi/gomqtt | broker/client.go | processPubrel | func (c *Client) processPubrel(id packet.ID) error {
// get stored publish packet from session
pkt, err := c.session.LookupPacket(session.Incoming, id)
if err != nil {
return c.die(SessionError, err)
}
// prepare pubcomp packet
pubcomp := packet.NewPubcomp()
pubcomp.ID = id
// get packet from store
publish... | go | func (c *Client) processPubrel(id packet.ID) error {
// get stored publish packet from session
pkt, err := c.session.LookupPacket(session.Incoming, id)
if err != nil {
return c.die(SessionError, err)
}
// prepare pubcomp packet
pubcomp := packet.NewPubcomp()
pubcomp.ID = id
// get packet from store
publish... | [
"func",
"(",
"c",
"*",
"Client",
")",
"processPubrel",
"(",
"id",
"packet",
".",
"ID",
")",
"error",
"{",
"// get stored publish packet from session",
"pkt",
",",
"err",
":=",
"c",
".",
"session",
".",
"LookupPacket",
"(",
"session",
".",
"Incoming",
",",
... | // handle an incoming pubrel packet | [
"handle",
"an",
"incoming",
"pubrel",
"packet"
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/broker/client.go#L858-L897 |
10,041 | 256dpi/gomqtt | broker/client.go | processDisconnect | func (c *Client) processDisconnect() error {
// clear will
c.will = nil
// mark client as cleanly disconnected
atomic.StoreUint32(&c.state, clientDisconnected)
// close underlying connection (triggers cleanup)
_ = c.conn.Close()
// ensure tomb is killed
c.tomb.Kill(ErrClientDisconnected)
c.backend.Log(Clie... | go | func (c *Client) processDisconnect() error {
// clear will
c.will = nil
// mark client as cleanly disconnected
atomic.StoreUint32(&c.state, clientDisconnected)
// close underlying connection (triggers cleanup)
_ = c.conn.Close()
// ensure tomb is killed
c.tomb.Kill(ErrClientDisconnected)
c.backend.Log(Clie... | [
"func",
"(",
"c",
"*",
"Client",
")",
"processDisconnect",
"(",
")",
"error",
"{",
"// clear will",
"c",
".",
"will",
"=",
"nil",
"\n\n",
"// mark client as cleanly disconnected",
"atomic",
".",
"StoreUint32",
"(",
"&",
"c",
".",
"state",
",",
"clientDisconnec... | // handle an incoming disconnect packet | [
"handle",
"an",
"incoming",
"disconnect",
"packet"
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/broker/client.go#L900-L916 |
10,042 | 256dpi/gomqtt | transport/net_server.go | CreateNetServer | func CreateNetServer(address string) (*NetServer, error) {
listener, err := net.Listen("tcp", address)
if err != nil {
return nil, err
}
return NewNetServer(listener), nil
} | go | func CreateNetServer(address string) (*NetServer, error) {
listener, err := net.Listen("tcp", address)
if err != nil {
return nil, err
}
return NewNetServer(listener), nil
} | [
"func",
"CreateNetServer",
"(",
"address",
"string",
")",
"(",
"*",
"NetServer",
",",
"error",
")",
"{",
"listener",
",",
"err",
":=",
"net",
".",
"Listen",
"(",
"\"",
"\"",
",",
"address",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
... | // CreateNetServer creates a new TCP server that listens on the provided address. | [
"CreateNetServer",
"creates",
"a",
"new",
"TCP",
"server",
"that",
"listens",
"on",
"the",
"provided",
"address",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/transport/net_server.go#L24-L31 |
10,043 | 256dpi/gomqtt | transport/net_server.go | CreateSecureNetServer | func CreateSecureNetServer(address string, config *tls.Config) (*NetServer, error) {
listener, err := tls.Listen("tcp", address, config)
if err != nil {
return nil, err
}
return NewNetServer(listener), nil
} | go | func CreateSecureNetServer(address string, config *tls.Config) (*NetServer, error) {
listener, err := tls.Listen("tcp", address, config)
if err != nil {
return nil, err
}
return NewNetServer(listener), nil
} | [
"func",
"CreateSecureNetServer",
"(",
"address",
"string",
",",
"config",
"*",
"tls",
".",
"Config",
")",
"(",
"*",
"NetServer",
",",
"error",
")",
"{",
"listener",
",",
"err",
":=",
"tls",
".",
"Listen",
"(",
"\"",
"\"",
",",
"address",
",",
"config",... | // CreateSecureNetServer creates a new TLS server that listens on the provided address. | [
"CreateSecureNetServer",
"creates",
"a",
"new",
"TLS",
"server",
"that",
"listens",
"on",
"the",
"provided",
"address",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/transport/net_server.go#L34-L41 |
10,044 | 256dpi/gomqtt | client/future/future.go | New | func New() *Future {
return &Future{
Data: new(sync.Map),
completeChannel: make(chan struct{}),
cancelChannel: make(chan struct{}),
}
} | go | func New() *Future {
return &Future{
Data: new(sync.Map),
completeChannel: make(chan struct{}),
cancelChannel: make(chan struct{}),
}
} | [
"func",
"New",
"(",
")",
"*",
"Future",
"{",
"return",
"&",
"Future",
"{",
"Data",
":",
"new",
"(",
"sync",
".",
"Map",
")",
",",
"completeChannel",
":",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
",",
"cancelChannel",
":",
"make",
"(",
"chan",
... | // New will return a new Future. | [
"New",
"will",
"return",
"a",
"new",
"Future",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/client/future/future.go#L26-L32 |
10,045 | 256dpi/gomqtt | client/future/future.go | Bind | func (f *Future) Bind(f2 *Future) {
select {
case <-f2.completeChannel:
f.Data = f2.Data
close(f.completeChannel)
case <-f2.cancelChannel:
f.Data = f2.Data
close(f.cancelChannel)
}
} | go | func (f *Future) Bind(f2 *Future) {
select {
case <-f2.completeChannel:
f.Data = f2.Data
close(f.completeChannel)
case <-f2.cancelChannel:
f.Data = f2.Data
close(f.cancelChannel)
}
} | [
"func",
"(",
"f",
"*",
"Future",
")",
"Bind",
"(",
"f2",
"*",
"Future",
")",
"{",
"select",
"{",
"case",
"<-",
"f2",
".",
"completeChannel",
":",
"f",
".",
"Data",
"=",
"f2",
".",
"Data",
"\n",
"close",
"(",
"f",
".",
"completeChannel",
")",
"\n"... | // Bind will tie the current future to the specified future. If the bound to
// future is completed or canceled the current will as well. Data saved in the
// bound future is copied to the current on complete and cancel. | [
"Bind",
"will",
"tie",
"the",
"current",
"future",
"to",
"the",
"specified",
"future",
".",
"If",
"the",
"bound",
"to",
"future",
"is",
"completed",
"or",
"canceled",
"the",
"current",
"will",
"as",
"well",
".",
"Data",
"saved",
"in",
"the",
"bound",
"fu... | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/client/future/future.go#L37-L46 |
10,046 | 256dpi/gomqtt | client/future/future.go | Wait | func (f *Future) Wait(timeout time.Duration) error {
select {
case <-f.completeChannel:
return nil
case <-f.cancelChannel:
return ErrCanceled
case <-time.After(timeout):
return ErrTimeout
}
} | go | func (f *Future) Wait(timeout time.Duration) error {
select {
case <-f.completeChannel:
return nil
case <-f.cancelChannel:
return ErrCanceled
case <-time.After(timeout):
return ErrTimeout
}
} | [
"func",
"(",
"f",
"*",
"Future",
")",
"Wait",
"(",
"timeout",
"time",
".",
"Duration",
")",
"error",
"{",
"select",
"{",
"case",
"<-",
"f",
".",
"completeChannel",
":",
"return",
"nil",
"\n",
"case",
"<-",
"f",
".",
"cancelChannel",
":",
"return",
"E... | // Wait will wait the given amount of time and return whether the future has been
// completed, canceled or the request timed out. | [
"Wait",
"will",
"wait",
"the",
"given",
"amount",
"of",
"time",
"and",
"return",
"whether",
"the",
"future",
"has",
"been",
"completed",
"canceled",
"or",
"the",
"request",
"timed",
"out",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/client/future/future.go#L50-L59 |
10,047 | 256dpi/gomqtt | topic/tree.go | Add | func (t *Tree) Add(topic string, value interface{}) {
t.mutex.Lock()
defer t.mutex.Unlock()
t.add(value, 0, strings.Split(topic, t.Separator), t.root)
} | go | func (t *Tree) Add(topic string, value interface{}) {
t.mutex.Lock()
defer t.mutex.Unlock()
t.add(value, 0, strings.Split(topic, t.Separator), t.root)
} | [
"func",
"(",
"t",
"*",
"Tree",
")",
"Add",
"(",
"topic",
"string",
",",
"value",
"interface",
"{",
"}",
")",
"{",
"t",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"t",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"t",
".",
"add",
"(... | // Add registers the value for the supplied topic. This function will
// automatically grow the tree. If value already exists for the given topic it
// will not be added again. | [
"Add",
"registers",
"the",
"value",
"for",
"the",
"supplied",
"topic",
".",
"This",
"function",
"will",
"automatically",
"grow",
"the",
"tree",
".",
"If",
"value",
"already",
"exists",
"for",
"the",
"given",
"topic",
"it",
"will",
"not",
"be",
"added",
"ag... | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/topic/tree.go#L78-L83 |
10,048 | 256dpi/gomqtt | topic/tree.go | Set | func (t *Tree) Set(topic string, value interface{}) {
t.mutex.Lock()
defer t.mutex.Unlock()
t.set(value, 0, strings.Split(topic, t.Separator), t.root)
} | go | func (t *Tree) Set(topic string, value interface{}) {
t.mutex.Lock()
defer t.mutex.Unlock()
t.set(value, 0, strings.Split(topic, t.Separator), t.root)
} | [
"func",
"(",
"t",
"*",
"Tree",
")",
"Set",
"(",
"topic",
"string",
",",
"value",
"interface",
"{",
"}",
")",
"{",
"t",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"t",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"t",
".",
"set",
"(... | // Set sets the supplied value as the only value for the supplied topic. This
// function will automatically grow the tree. | [
"Set",
"sets",
"the",
"supplied",
"value",
"as",
"the",
"only",
"value",
"for",
"the",
"supplied",
"topic",
".",
"This",
"function",
"will",
"automatically",
"grow",
"the",
"tree",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/topic/tree.go#L112-L117 |
10,049 | 256dpi/gomqtt | topic/tree.go | Get | func (t *Tree) Get(topic string) []interface{} {
t.mutex.Lock()
defer t.mutex.Unlock()
return t.get(0, strings.Split(topic, t.Separator), t.root)
} | go | func (t *Tree) Get(topic string) []interface{} {
t.mutex.Lock()
defer t.mutex.Unlock()
return t.get(0, strings.Split(topic, t.Separator), t.root)
} | [
"func",
"(",
"t",
"*",
"Tree",
")",
"Get",
"(",
"topic",
"string",
")",
"[",
"]",
"interface",
"{",
"}",
"{",
"t",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"t",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"return",
"t",
".",
"ge... | // Get gets the values from the topic that exactly matches the supplied topics. | [
"Get",
"gets",
"the",
"values",
"from",
"the",
"topic",
"that",
"exactly",
"matches",
"the",
"supplied",
"topics",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/topic/tree.go#L139-L144 |
10,050 | 256dpi/gomqtt | topic/tree.go | Remove | func (t *Tree) Remove(topic string, value interface{}) {
t.mutex.Lock()
defer t.mutex.Unlock()
t.remove(value, 0, strings.Split(topic, t.Separator), t.root)
} | go | func (t *Tree) Remove(topic string, value interface{}) {
t.mutex.Lock()
defer t.mutex.Unlock()
t.remove(value, 0, strings.Split(topic, t.Separator), t.root)
} | [
"func",
"(",
"t",
"*",
"Tree",
")",
"Remove",
"(",
"topic",
"string",
",",
"value",
"interface",
"{",
"}",
")",
"{",
"t",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"t",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"t",
".",
"remove"... | // Remove un-registers the value from the supplied topic. This function will
// automatically shrink the tree. | [
"Remove",
"un",
"-",
"registers",
"the",
"value",
"from",
"the",
"supplied",
"topic",
".",
"This",
"function",
"will",
"automatically",
"shrink",
"the",
"tree",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/topic/tree.go#L164-L169 |
10,051 | 256dpi/gomqtt | topic/tree.go | Empty | func (t *Tree) Empty(topic string) {
t.mutex.Lock()
defer t.mutex.Unlock()
t.remove(nil, 0, strings.Split(topic, t.Separator), t.root)
} | go | func (t *Tree) Empty(topic string) {
t.mutex.Lock()
defer t.mutex.Unlock()
t.remove(nil, 0, strings.Split(topic, t.Separator), t.root)
} | [
"func",
"(",
"t",
"*",
"Tree",
")",
"Empty",
"(",
"topic",
"string",
")",
"{",
"t",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"t",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"t",
".",
"remove",
"(",
"nil",
",",
"0",
",",
"string... | // Empty will unregister all values from the supplied topic. This function will
// automatically shrink the tree. | [
"Empty",
"will",
"unregister",
"all",
"values",
"from",
"the",
"supplied",
"topic",
".",
"This",
"function",
"will",
"automatically",
"shrink",
"the",
"tree",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/topic/tree.go#L173-L178 |
10,052 | 256dpi/gomqtt | topic/tree.go | Clear | func (t *Tree) Clear(value interface{}) {
t.mutex.Lock()
defer t.mutex.Unlock()
t.clear(value, t.root)
} | go | func (t *Tree) Clear(value interface{}) {
t.mutex.Lock()
defer t.mutex.Unlock()
t.clear(value, t.root)
} | [
"func",
"(",
"t",
"*",
"Tree",
")",
"Clear",
"(",
"value",
"interface",
"{",
"}",
")",
"{",
"t",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"t",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"t",
".",
"clear",
"(",
"value",
",",
"t"... | // Clear will unregister the supplied value from all topics. This function will
// automatically shrink the tree. | [
"Clear",
"will",
"unregister",
"the",
"supplied",
"value",
"from",
"all",
"topics",
".",
"This",
"function",
"will",
"automatically",
"shrink",
"the",
"tree",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/topic/tree.go#L209-L214 |
10,053 | 256dpi/gomqtt | topic/tree.go | MatchFirst | func (t *Tree) MatchFirst(topic string) interface{} {
values := t.Match(topic)
if len(values) > 0 {
return values[0]
}
return nil
} | go | func (t *Tree) MatchFirst(topic string) interface{} {
values := t.Match(topic)
if len(values) > 0 {
return values[0]
}
return nil
} | [
"func",
"(",
"t",
"*",
"Tree",
")",
"MatchFirst",
"(",
"topic",
"string",
")",
"interface",
"{",
"}",
"{",
"values",
":=",
"t",
".",
"Match",
"(",
"topic",
")",
"\n\n",
"if",
"len",
"(",
"values",
")",
">",
"0",
"{",
"return",
"values",
"[",
"0",... | // MatchFirst will run Match and return the first value or nil. | [
"MatchFirst",
"will",
"run",
"Match",
"and",
"return",
"the",
"first",
"value",
"or",
"nil",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/topic/tree.go#L273-L281 |
10,054 | 256dpi/gomqtt | topic/tree.go | SearchFirst | func (t *Tree) SearchFirst(topic string) interface{} {
values := t.Search(topic)
if len(values) > 0 {
return values[0]
}
return nil
} | go | func (t *Tree) SearchFirst(topic string) interface{} {
values := t.Search(topic)
if len(values) > 0 {
return values[0]
}
return nil
} | [
"func",
"(",
"t",
"*",
"Tree",
")",
"SearchFirst",
"(",
"topic",
"string",
")",
"interface",
"{",
"}",
"{",
"values",
":=",
"t",
".",
"Search",
"(",
"topic",
")",
"\n\n",
"if",
"len",
"(",
"values",
")",
">",
"0",
"{",
"return",
"values",
"[",
"0... | // SearchFirst will run Search and return the first value or nil. | [
"SearchFirst",
"will",
"run",
"Search",
"and",
"return",
"the",
"first",
"value",
"or",
"nil",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/topic/tree.go#L336-L344 |
10,055 | 256dpi/gomqtt | topic/tree.go | clean | func (t *Tree) clean(values []interface{}) []interface{} {
result := values[:0]
for _, v := range values {
if contains(result, v) {
continue
}
result = append(result, v)
}
return result
} | go | func (t *Tree) clean(values []interface{}) []interface{} {
result := values[:0]
for _, v := range values {
if contains(result, v) {
continue
}
result = append(result, v)
}
return result
} | [
"func",
"(",
"t",
"*",
"Tree",
")",
"clean",
"(",
"values",
"[",
"]",
"interface",
"{",
"}",
")",
"[",
"]",
"interface",
"{",
"}",
"{",
"result",
":=",
"values",
"[",
":",
"0",
"]",
"\n\n",
"for",
"_",
",",
"v",
":=",
"range",
"values",
"{",
... | // clean will remove duplicates | [
"clean",
"will",
"remove",
"duplicates"
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/topic/tree.go#L347-L359 |
10,056 | 256dpi/gomqtt | topic/tree.go | All | func (t *Tree) All() []interface{} {
t.mutex.RLock()
defer t.mutex.RUnlock()
return t.clean(t.all([]interface{}{}, t.root))
} | go | func (t *Tree) All() []interface{} {
t.mutex.RLock()
defer t.mutex.RUnlock()
return t.clean(t.all([]interface{}{}, t.root))
} | [
"func",
"(",
"t",
"*",
"Tree",
")",
"All",
"(",
")",
"[",
"]",
"interface",
"{",
"}",
"{",
"t",
".",
"mutex",
".",
"RLock",
"(",
")",
"\n",
"defer",
"t",
".",
"mutex",
".",
"RUnlock",
"(",
")",
"\n\n",
"return",
"t",
".",
"clean",
"(",
"t",
... | // All will return all stored values in the tree. | [
"All",
"will",
"return",
"all",
"stored",
"values",
"in",
"the",
"tree",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/topic/tree.go#L384-L389 |
10,057 | 256dpi/gomqtt | topic/tree.go | Reset | func (t *Tree) Reset() {
t.mutex.Lock()
defer t.mutex.Unlock()
t.root = newNode()
} | go | func (t *Tree) Reset() {
t.mutex.Lock()
defer t.mutex.Unlock()
t.root = newNode()
} | [
"func",
"(",
"t",
"*",
"Tree",
")",
"Reset",
"(",
")",
"{",
"t",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"t",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"t",
".",
"root",
"=",
"newNode",
"(",
")",
"\n",
"}"
] | // Reset will completely clear the tree. | [
"Reset",
"will",
"completely",
"clear",
"the",
"tree",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/topic/tree.go#L402-L407 |
10,058 | 256dpi/gomqtt | topic/tree.go | String | func (t *Tree) String() string {
t.mutex.RLock()
defer t.mutex.RUnlock()
return fmt.Sprintf("topic.Tree:%s", t.root.string(0))
} | go | func (t *Tree) String() string {
t.mutex.RLock()
defer t.mutex.RUnlock()
return fmt.Sprintf("topic.Tree:%s", t.root.string(0))
} | [
"func",
"(",
"t",
"*",
"Tree",
")",
"String",
"(",
")",
"string",
"{",
"t",
".",
"mutex",
".",
"RLock",
"(",
")",
"\n",
"defer",
"t",
".",
"mutex",
".",
"RUnlock",
"(",
")",
"\n\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"t",
... | // String will return a string representation of the tree. | [
"String",
"will",
"return",
"a",
"string",
"representation",
"of",
"the",
"tree",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/topic/tree.go#L410-L415 |
10,059 | 256dpi/gomqtt | spec/spec.go | AllFeatures | func AllFeatures() *Config {
return &Config{
RetainedMessages: true,
StoredPackets: true,
StoredSubscriptions: true,
OfflineSubscriptions: true,
Authentication: true,
UniqueClientIDs: true,
RootSlashDistinction: true,
}
} | go | func AllFeatures() *Config {
return &Config{
RetainedMessages: true,
StoredPackets: true,
StoredSubscriptions: true,
OfflineSubscriptions: true,
Authentication: true,
UniqueClientIDs: true,
RootSlashDistinction: true,
}
} | [
"func",
"AllFeatures",
"(",
")",
"*",
"Config",
"{",
"return",
"&",
"Config",
"{",
"RetainedMessages",
":",
"true",
",",
"StoredPackets",
":",
"true",
",",
"StoredSubscriptions",
":",
"true",
",",
"OfflineSubscriptions",
":",
"true",
",",
"Authentication",
":"... | // AllFeatures returns a config that enables all features. | [
"AllFeatures",
"returns",
"a",
"config",
"that",
"enables",
"all",
"features",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/spec/spec.go#L43-L53 |
10,060 | 256dpi/gomqtt | packet/type.go | String | func (t Type) String() string {
switch t {
case CONNECT:
return "Connect"
case CONNACK:
return "Connack"
case PUBLISH:
return "Publish"
case PUBACK:
return "Puback"
case PUBREC:
return "Pubrec"
case PUBREL:
return "Pubrel"
case PUBCOMP:
return "Pubcomp"
case SUBSCRIBE:
return "Subscribe"
case ... | go | func (t Type) String() string {
switch t {
case CONNECT:
return "Connect"
case CONNACK:
return "Connack"
case PUBLISH:
return "Publish"
case PUBACK:
return "Puback"
case PUBREC:
return "Pubrec"
case PUBREL:
return "Pubrel"
case PUBCOMP:
return "Pubcomp"
case SUBSCRIBE:
return "Subscribe"
case ... | [
"func",
"(",
"t",
"Type",
")",
"String",
"(",
")",
"string",
"{",
"switch",
"t",
"{",
"case",
"CONNECT",
":",
"return",
"\"",
"\"",
"\n",
"case",
"CONNACK",
":",
"return",
"\"",
"\"",
"\n",
"case",
"PUBLISH",
":",
"return",
"\"",
"\"",
"\n",
"case"... | // String returns the type as a string. | [
"String",
"returns",
"the",
"type",
"as",
"a",
"string",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/packet/type.go#L31-L64 |
10,061 | 256dpi/gomqtt | packet/type.go | defaultFlags | func (t Type) defaultFlags() byte {
switch t {
case CONNECT:
return 0
case CONNACK:
return 0
case PUBACK:
return 0
case PUBREC:
return 0
case PUBREL:
return 2 // 00000010
case PUBCOMP:
return 0
case SUBSCRIBE:
return 2 // 00000010
case SUBACK:
return 0
case UNSUBSCRIBE:
return 2 // 00000010
... | go | func (t Type) defaultFlags() byte {
switch t {
case CONNECT:
return 0
case CONNACK:
return 0
case PUBACK:
return 0
case PUBREC:
return 0
case PUBREL:
return 2 // 00000010
case PUBCOMP:
return 0
case SUBSCRIBE:
return 2 // 00000010
case SUBACK:
return 0
case UNSUBSCRIBE:
return 2 // 00000010
... | [
"func",
"(",
"t",
"Type",
")",
"defaultFlags",
"(",
")",
"byte",
"{",
"switch",
"t",
"{",
"case",
"CONNECT",
":",
"return",
"0",
"\n",
"case",
"CONNACK",
":",
"return",
"0",
"\n",
"case",
"PUBACK",
":",
"return",
"0",
"\n",
"case",
"PUBREC",
":",
"... | // DefaultFlags returns the default flag values for the packet type, as defined
// by the MQTT spec, except for PUBLISH. | [
"DefaultFlags",
"returns",
"the",
"default",
"flag",
"values",
"for",
"the",
"packet",
"type",
"as",
"defined",
"by",
"the",
"MQTT",
"spec",
"except",
"for",
"PUBLISH",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/packet/type.go#L68-L99 |
10,062 | 256dpi/gomqtt | transport/websocket_server.go | NewWebSocketServer | func NewWebSocketServer(listener net.Listener) *WebSocketServer {
// create server
ws := &WebSocketServer{
listener: listener,
upgrader: &websocket.Upgrader{
HandshakeTimeout: 60 * time.Second,
Subprotocols: []string{"mqtt", "mqttv3.1"},
},
incoming: make(chan *WebSocketConn),
}
// add check orig... | go | func NewWebSocketServer(listener net.Listener) *WebSocketServer {
// create server
ws := &WebSocketServer{
listener: listener,
upgrader: &websocket.Upgrader{
HandshakeTimeout: 60 * time.Second,
Subprotocols: []string{"mqtt", "mqttv3.1"},
},
incoming: make(chan *WebSocketConn),
}
// add check orig... | [
"func",
"NewWebSocketServer",
"(",
"listener",
"net",
".",
"Listener",
")",
"*",
"WebSocketServer",
"{",
"// create server",
"ws",
":=",
"&",
"WebSocketServer",
"{",
"listener",
":",
"listener",
",",
"upgrader",
":",
"&",
"websocket",
".",
"Upgrader",
"{",
"Ha... | // NewWebSocketServer wraps the provided listener. | [
"NewWebSocketServer",
"wraps",
"the",
"provided",
"listener",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/transport/websocket_server.go#L31-L62 |
10,063 | 256dpi/gomqtt | transport/websocket_server.go | CreateWebSocketServer | func CreateWebSocketServer(address string) (*WebSocketServer, error) {
listener, err := net.Listen("tcp", address)
if err != nil {
return nil, err
}
return NewWebSocketServer(listener), nil
} | go | func CreateWebSocketServer(address string) (*WebSocketServer, error) {
listener, err := net.Listen("tcp", address)
if err != nil {
return nil, err
}
return NewWebSocketServer(listener), nil
} | [
"func",
"CreateWebSocketServer",
"(",
"address",
"string",
")",
"(",
"*",
"WebSocketServer",
",",
"error",
")",
"{",
"listener",
",",
"err",
":=",
"net",
".",
"Listen",
"(",
"\"",
"\"",
",",
"address",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return"... | // CreateWebSocketServer creates a new WS server that listens on the provided address. | [
"CreateWebSocketServer",
"creates",
"a",
"new",
"WS",
"server",
"that",
"listens",
"on",
"the",
"provided",
"address",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/transport/websocket_server.go#L65-L72 |
10,064 | 256dpi/gomqtt | transport/websocket_server.go | CreateSecureWebSocketServer | func CreateSecureWebSocketServer(address string, config *tls.Config) (*WebSocketServer, error) {
listener, err := tls.Listen("tcp", address, config)
if err != nil {
return nil, err
}
return NewWebSocketServer(listener), nil
} | go | func CreateSecureWebSocketServer(address string, config *tls.Config) (*WebSocketServer, error) {
listener, err := tls.Listen("tcp", address, config)
if err != nil {
return nil, err
}
return NewWebSocketServer(listener), nil
} | [
"func",
"CreateSecureWebSocketServer",
"(",
"address",
"string",
",",
"config",
"*",
"tls",
".",
"Config",
")",
"(",
"*",
"WebSocketServer",
",",
"error",
")",
"{",
"listener",
",",
"err",
":=",
"tls",
".",
"Listen",
"(",
"\"",
"\"",
",",
"address",
",",... | // CreateSecureWebSocketServer creates a new WSS server that listens on the
// provided address. | [
"CreateSecureWebSocketServer",
"creates",
"a",
"new",
"WSS",
"server",
"that",
"listens",
"on",
"the",
"provided",
"address",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/transport/websocket_server.go#L76-L83 |
10,065 | 256dpi/gomqtt | transport/websocket_server.go | SetOriginChecker | func (s *WebSocketServer) SetOriginChecker(fn func(r *http.Request) bool) {
s.originChecker = fn
} | go | func (s *WebSocketServer) SetOriginChecker(fn func(r *http.Request) bool) {
s.originChecker = fn
} | [
"func",
"(",
"s",
"*",
"WebSocketServer",
")",
"SetOriginChecker",
"(",
"fn",
"func",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"bool",
")",
"{",
"s",
".",
"originChecker",
"=",
"fn",
"\n",
"}"
] | // SetOriginChecker sets an optional function that allows check the request origin
// before accepting the connection. | [
"SetOriginChecker",
"sets",
"an",
"optional",
"function",
"that",
"allows",
"check",
"the",
"request",
"origin",
"before",
"accepting",
"the",
"connection",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/transport/websocket_server.go#L93-L95 |
10,066 | 256dpi/gomqtt | client/service.go | NewService | func NewService(queueSize ...int) *Service {
var qs = 100
if len(queueSize) > 0 {
qs = queueSize[0]
}
return &Service{
state: serviceStopped,
Session: session.NewMemorySession(),
MinReconnectDelay: 50 * time.Millisecond,
MaxReconnectDelay: 10 ... | go | func NewService(queueSize ...int) *Service {
var qs = 100
if len(queueSize) > 0 {
qs = queueSize[0]
}
return &Service{
state: serviceStopped,
Session: session.NewMemorySession(),
MinReconnectDelay: 50 * time.Millisecond,
MaxReconnectDelay: 10 ... | [
"func",
"NewService",
"(",
"queueSize",
"...",
"int",
")",
"*",
"Service",
"{",
"var",
"qs",
"=",
"100",
"\n",
"if",
"len",
"(",
"queueSize",
")",
">",
"0",
"{",
"qs",
"=",
"queueSize",
"[",
"0",
"]",
"\n",
"}",
"\n\n",
"return",
"&",
"Service",
... | // NewService allocates and returns a new service. The optional parameter queueSize
// specifies how many Subscribe, Unsubscribe and Publish commands can be queued
// up before actually sending them on the wire. The default queueSize is 100. | [
"NewService",
"allocates",
"and",
"returns",
"a",
"new",
"service",
".",
"The",
"optional",
"parameter",
"queueSize",
"specifies",
"how",
"many",
"Subscribe",
"Unsubscribe",
"and",
"Publish",
"commands",
"can",
"be",
"queued",
"up",
"before",
"actually",
"sending"... | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/client/service.go#L131-L150 |
10,067 | 256dpi/gomqtt | client/service.go | Start | func (s *Service) Start(config *Config) {
if config == nil {
panic("no config specified")
}
s.mutex.Lock()
defer s.mutex.Unlock()
// return if already started
if atomic.LoadUint32(&s.state) == serviceStarted {
return
}
// set state
atomic.StoreUint32(&s.state, serviceStarted)
// save config
s.config ... | go | func (s *Service) Start(config *Config) {
if config == nil {
panic("no config specified")
}
s.mutex.Lock()
defer s.mutex.Unlock()
// return if already started
if atomic.LoadUint32(&s.state) == serviceStarted {
return
}
// set state
atomic.StoreUint32(&s.state, serviceStarted)
// save config
s.config ... | [
"func",
"(",
"s",
"*",
"Service",
")",
"Start",
"(",
"config",
"*",
"Config",
")",
"{",
"if",
"config",
"==",
"nil",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"s",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"mu... | // Start will start the service with the specified configuration. From now on
// the service will automatically reconnect on any error until Stop is called. | [
"Start",
"will",
"start",
"the",
"service",
"with",
"the",
"specified",
"configuration",
".",
"From",
"now",
"on",
"the",
"service",
"will",
"automatically",
"reconnect",
"on",
"any",
"error",
"until",
"Stop",
"is",
"called",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/client/service.go#L154-L188 |
10,068 | 256dpi/gomqtt | client/service.go | PublishMessage | func (s *Service) PublishMessage(msg *packet.Message) GenericFuture {
s.mutex.Lock()
defer s.mutex.Unlock()
// allocate future
f := future.New()
// queue publish
s.commandQueue <- &command{
publish: true,
future: f,
message: msg,
}
return f
} | go | func (s *Service) PublishMessage(msg *packet.Message) GenericFuture {
s.mutex.Lock()
defer s.mutex.Unlock()
// allocate future
f := future.New()
// queue publish
s.commandQueue <- &command{
publish: true,
future: f,
message: msg,
}
return f
} | [
"func",
"(",
"s",
"*",
"Service",
")",
"PublishMessage",
"(",
"msg",
"*",
"packet",
".",
"Message",
")",
"GenericFuture",
"{",
"s",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"// allocate f... | // PublishMessage will send a Publish packet containing the passed message. It will
// return a PublishFuture that gets completed once the quality of service flow
// has been completed. | [
"PublishMessage",
"will",
"send",
"a",
"Publish",
"packet",
"containing",
"the",
"passed",
"message",
".",
"It",
"will",
"return",
"a",
"PublishFuture",
"that",
"gets",
"completed",
"once",
"the",
"quality",
"of",
"service",
"flow",
"has",
"been",
"completed",
... | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/client/service.go#L207-L222 |
10,069 | 256dpi/gomqtt | client/service.go | Subscribe | func (s *Service) Subscribe(topic string, qos packet.QOS) SubscribeFuture {
return s.SubscribeMultiple([]packet.Subscription{
{Topic: topic, QOS: qos},
})
} | go | func (s *Service) Subscribe(topic string, qos packet.QOS) SubscribeFuture {
return s.SubscribeMultiple([]packet.Subscription{
{Topic: topic, QOS: qos},
})
} | [
"func",
"(",
"s",
"*",
"Service",
")",
"Subscribe",
"(",
"topic",
"string",
",",
"qos",
"packet",
".",
"QOS",
")",
"SubscribeFuture",
"{",
"return",
"s",
".",
"SubscribeMultiple",
"(",
"[",
"]",
"packet",
".",
"Subscription",
"{",
"{",
"Topic",
":",
"t... | // Subscribe will send a Subscribe packet containing one topic to subscribe. It
// will return a SubscribeFuture that gets completed once the acknowledgements
// have been received. | [
"Subscribe",
"will",
"send",
"a",
"Subscribe",
"packet",
"containing",
"one",
"topic",
"to",
"subscribe",
".",
"It",
"will",
"return",
"a",
"SubscribeFuture",
"that",
"gets",
"completed",
"once",
"the",
"acknowledgements",
"have",
"been",
"received",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/client/service.go#L227-L231 |
10,070 | 256dpi/gomqtt | client/service.go | SubscribeMultiple | func (s *Service) SubscribeMultiple(subscriptions []packet.Subscription) SubscribeFuture {
s.mutex.Lock()
defer s.mutex.Unlock()
// save subscription
for _, v := range subscriptions {
s.subscriptions.Set(v.Topic, v)
}
// allocate future
f := future.New()
// queue subscribe
s.commandQueue <- &command{
su... | go | func (s *Service) SubscribeMultiple(subscriptions []packet.Subscription) SubscribeFuture {
s.mutex.Lock()
defer s.mutex.Unlock()
// save subscription
for _, v := range subscriptions {
s.subscriptions.Set(v.Topic, v)
}
// allocate future
f := future.New()
// queue subscribe
s.commandQueue <- &command{
su... | [
"func",
"(",
"s",
"*",
"Service",
")",
"SubscribeMultiple",
"(",
"subscriptions",
"[",
"]",
"packet",
".",
"Subscription",
")",
"SubscribeFuture",
"{",
"s",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"mutex",
".",
"Unlock",
"(",
")",... | // SubscribeMultiple will send a Subscribe packet containing multiple topics to
// subscribe. It will return a SubscribeFuture that gets completed once the
// acknowledgements have been received. | [
"SubscribeMultiple",
"will",
"send",
"a",
"Subscribe",
"packet",
"containing",
"multiple",
"topics",
"to",
"subscribe",
".",
"It",
"will",
"return",
"a",
"SubscribeFuture",
"that",
"gets",
"completed",
"once",
"the",
"acknowledgements",
"have",
"been",
"received",
... | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/client/service.go#L236-L256 |
10,071 | 256dpi/gomqtt | client/service.go | Unsubscribe | func (s *Service) Unsubscribe(topic string) GenericFuture {
return s.UnsubscribeMultiple([]string{topic})
} | go | func (s *Service) Unsubscribe(topic string) GenericFuture {
return s.UnsubscribeMultiple([]string{topic})
} | [
"func",
"(",
"s",
"*",
"Service",
")",
"Unsubscribe",
"(",
"topic",
"string",
")",
"GenericFuture",
"{",
"return",
"s",
".",
"UnsubscribeMultiple",
"(",
"[",
"]",
"string",
"{",
"topic",
"}",
")",
"\n",
"}"
] | // Unsubscribe will send a Unsubscribe packet containing one topic to unsubscribe.
// It will return a SubscribeFuture that gets completed once the acknowledgements
// have been received. | [
"Unsubscribe",
"will",
"send",
"a",
"Unsubscribe",
"packet",
"containing",
"one",
"topic",
"to",
"unsubscribe",
".",
"It",
"will",
"return",
"a",
"SubscribeFuture",
"that",
"gets",
"completed",
"once",
"the",
"acknowledgements",
"have",
"been",
"received",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/client/service.go#L261-L263 |
10,072 | 256dpi/gomqtt | client/service.go | UnsubscribeMultiple | func (s *Service) UnsubscribeMultiple(topics []string) GenericFuture {
s.mutex.Lock()
defer s.mutex.Unlock()
// remove subscription
for _, v := range topics {
s.subscriptions.Empty(v)
}
// allocate future
f := future.New()
// queue unsubscribe
s.commandQueue <- &command{
unsubscribe: true,
future: ... | go | func (s *Service) UnsubscribeMultiple(topics []string) GenericFuture {
s.mutex.Lock()
defer s.mutex.Unlock()
// remove subscription
for _, v := range topics {
s.subscriptions.Empty(v)
}
// allocate future
f := future.New()
// queue unsubscribe
s.commandQueue <- &command{
unsubscribe: true,
future: ... | [
"func",
"(",
"s",
"*",
"Service",
")",
"UnsubscribeMultiple",
"(",
"topics",
"[",
"]",
"string",
")",
"GenericFuture",
"{",
"s",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"// remove subscrip... | // UnsubscribeMultiple will send a Unsubscribe packet containing multiple
// topics to unsubscribe. It will return a SubscribeFuture that gets completed
// once the acknowledgements have been received. | [
"UnsubscribeMultiple",
"will",
"send",
"a",
"Unsubscribe",
"packet",
"containing",
"multiple",
"topics",
"to",
"unsubscribe",
".",
"It",
"will",
"return",
"a",
"SubscribeFuture",
"that",
"gets",
"completed",
"once",
"the",
"acknowledgements",
"have",
"been",
"receiv... | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/client/service.go#L268-L288 |
10,073 | 256dpi/gomqtt | client/service.go | supervisor | func (s *Service) supervisor() error {
first := true
for {
if first {
// no delay on first attempt
first = false
} else {
// get backoff duration
d := s.backoff.Duration()
s.log(fmt.Sprintf("Delay Reconnect: %v", d))
// sleep but return on Stop
select {
case <-time.After(d):
case <-s.... | go | func (s *Service) supervisor() error {
first := true
for {
if first {
// no delay on first attempt
first = false
} else {
// get backoff duration
d := s.backoff.Duration()
s.log(fmt.Sprintf("Delay Reconnect: %v", d))
// sleep but return on Stop
select {
case <-time.After(d):
case <-s.... | [
"func",
"(",
"s",
"*",
"Service",
")",
"supervisor",
"(",
")",
"error",
"{",
"first",
":=",
"true",
"\n\n",
"for",
"{",
"if",
"first",
"{",
"// no delay on first attempt",
"first",
"=",
"false",
"\n",
"}",
"else",
"{",
"// get backoff duration",
"d",
":=",... | // the supervised reconnect loop | [
"the",
"supervised",
"reconnect",
"loop"
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/client/service.go#L319-L375 |
10,074 | 256dpi/gomqtt | client/service.go | connect | func (s *Service) connect(fail chan struct{}) (*Client, bool) {
// prepare new client
client := New()
client.Session = s.Session
client.Logger = s.Logger
client.futureStore = s.futureStore
// set callback
client.Callback = func(msg *packet.Message, err error) error {
if err != nil {
s.err("Client", err)
... | go | func (s *Service) connect(fail chan struct{}) (*Client, bool) {
// prepare new client
client := New()
client.Session = s.Session
client.Logger = s.Logger
client.futureStore = s.futureStore
// set callback
client.Callback = func(msg *packet.Message, err error) error {
if err != nil {
s.err("Client", err)
... | [
"func",
"(",
"s",
"*",
"Service",
")",
"connect",
"(",
"fail",
"chan",
"struct",
"{",
"}",
")",
"(",
"*",
"Client",
",",
"bool",
")",
"{",
"// prepare new client",
"client",
":=",
"New",
"(",
")",
"\n",
"client",
".",
"Session",
"=",
"s",
".",
"Ses... | // will try to connect one client to the broker | [
"will",
"try",
"to",
"connect",
"one",
"client",
"to",
"the",
"broker"
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/client/service.go#L378-L426 |
10,075 | 256dpi/gomqtt | client/service.go | dispatcher | func (s *Service) dispatcher(client *Client, fail chan struct{}) bool {
for {
select {
case cmd := <-s.commandQueue:
// handle subscribe command
if cmd.subscribe {
f2, err := client.SubscribeMultiple(cmd.subscriptions)
if err != nil {
s.err("Subscribe", err)
// cancel future
cmd.futu... | go | func (s *Service) dispatcher(client *Client, fail chan struct{}) bool {
for {
select {
case cmd := <-s.commandQueue:
// handle subscribe command
if cmd.subscribe {
f2, err := client.SubscribeMultiple(cmd.subscriptions)
if err != nil {
s.err("Subscribe", err)
// cancel future
cmd.futu... | [
"func",
"(",
"s",
"*",
"Service",
")",
"dispatcher",
"(",
"client",
"*",
"Client",
",",
"fail",
"chan",
"struct",
"{",
"}",
")",
"bool",
"{",
"for",
"{",
"select",
"{",
"case",
"cmd",
":=",
"<-",
"s",
".",
"commandQueue",
":",
"// handle subscribe comm... | // reads from the queues and calls the current client | [
"reads",
"from",
"the",
"queues",
"and",
"calls",
"the",
"current",
"client"
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/client/service.go#L474-L541 |
10,076 | 256dpi/gomqtt | packet/connack.go | String | func (cc ConnackCode) String() string {
switch cc {
case ConnectionAccepted:
return "connection accepted"
case InvalidProtocolVersion:
return "connection refused: unacceptable protocol version"
case IdentifierRejected:
return "connection refused: identifier rejected"
case ServerUnavailable:
return "connect... | go | func (cc ConnackCode) String() string {
switch cc {
case ConnectionAccepted:
return "connection accepted"
case InvalidProtocolVersion:
return "connection refused: unacceptable protocol version"
case IdentifierRejected:
return "connection refused: identifier rejected"
case ServerUnavailable:
return "connect... | [
"func",
"(",
"cc",
"ConnackCode",
")",
"String",
"(",
")",
"string",
"{",
"switch",
"cc",
"{",
"case",
"ConnectionAccepted",
":",
"return",
"\"",
"\"",
"\n",
"case",
"InvalidProtocolVersion",
":",
"return",
"\"",
"\"",
"\n",
"case",
"IdentifierRejected",
":"... | // String returns the corresponding error string for the ConnackCode. | [
"String",
"returns",
"the",
"corresponding",
"error",
"string",
"for",
"the",
"ConnackCode",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/packet/connack.go#L24-L41 |
10,077 | 256dpi/gomqtt | client/tools.go | ClearSession | func ClearSession(config *Config, timeout time.Duration) error {
// copy config
newConfig := *config
newConfig.CleanSession = true
// create client
client := New()
// connect to broker
future, err := client.Connect(&newConfig)
if err != nil {
return err
}
// wait for future
err = future.Wait(timeout)
i... | go | func ClearSession(config *Config, timeout time.Duration) error {
// copy config
newConfig := *config
newConfig.CleanSession = true
// create client
client := New()
// connect to broker
future, err := client.Connect(&newConfig)
if err != nil {
return err
}
// wait for future
err = future.Wait(timeout)
i... | [
"func",
"ClearSession",
"(",
"config",
"*",
"Config",
",",
"timeout",
"time",
".",
"Duration",
")",
"error",
"{",
"// copy config",
"newConfig",
":=",
"*",
"config",
"\n",
"newConfig",
".",
"CleanSession",
"=",
"true",
"\n\n",
"// create client",
"client",
":=... | // ClearSession will connect to the specified broker and request a clean session. | [
"ClearSession",
"will",
"connect",
"to",
"the",
"specified",
"broker",
"and",
"request",
"a",
"clean",
"session",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/client/tools.go#L10-L37 |
10,078 | 256dpi/gomqtt | client/tools.go | PublishMessage | func PublishMessage(config *Config, msg *packet.Message, timeout time.Duration) error {
// create client
client := New()
// connect to broker
future, err := client.Connect(config)
if err != nil {
return err
}
// wait on future
err = future.Wait(timeout)
if err != nil {
return err
}
// publish message
... | go | func PublishMessage(config *Config, msg *packet.Message, timeout time.Duration) error {
// create client
client := New()
// connect to broker
future, err := client.Connect(config)
if err != nil {
return err
}
// wait on future
err = future.Wait(timeout)
if err != nil {
return err
}
// publish message
... | [
"func",
"PublishMessage",
"(",
"config",
"*",
"Config",
",",
"msg",
"*",
"packet",
".",
"Message",
",",
"timeout",
"time",
".",
"Duration",
")",
"error",
"{",
"// create client",
"client",
":=",
"New",
"(",
")",
"\n\n",
"// connect to broker",
"future",
",",... | // PublishMessage will connect to the specified broker to publish the passed message. | [
"PublishMessage",
"will",
"connect",
"to",
"the",
"specified",
"broker",
"to",
"publish",
"the",
"passed",
"message",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/client/tools.go#L40-L75 |
10,079 | 256dpi/gomqtt | client/tools.go | ClearRetainedMessage | func ClearRetainedMessage(config *Config, topic string, timeout time.Duration) error {
return PublishMessage(config, &packet.Message{
Topic: topic,
Payload: nil,
QOS: 0,
Retain: true,
}, timeout)
} | go | func ClearRetainedMessage(config *Config, topic string, timeout time.Duration) error {
return PublishMessage(config, &packet.Message{
Topic: topic,
Payload: nil,
QOS: 0,
Retain: true,
}, timeout)
} | [
"func",
"ClearRetainedMessage",
"(",
"config",
"*",
"Config",
",",
"topic",
"string",
",",
"timeout",
"time",
".",
"Duration",
")",
"error",
"{",
"return",
"PublishMessage",
"(",
"config",
",",
"&",
"packet",
".",
"Message",
"{",
"Topic",
":",
"topic",
","... | // ClearRetainedMessage will connect to the specified broker and send an empty
// retained message to force any already retained message to be cleared. | [
"ClearRetainedMessage",
"will",
"connect",
"to",
"the",
"specified",
"broker",
"and",
"send",
"an",
"empty",
"retained",
"message",
"to",
"force",
"any",
"already",
"retained",
"message",
"to",
"be",
"cleared",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/client/tools.go#L79-L86 |
10,080 | 256dpi/gomqtt | client/tools.go | ReceiveMessage | func ReceiveMessage(config *Config, topic string, qos packet.QOS, timeout time.Duration) (*packet.Message, error) {
// create client
client := New()
// connect to broker
future, err := client.Connect(config)
if err != nil {
return nil, err
}
// wait for future
err = future.Wait(timeout)
if err != nil {
r... | go | func ReceiveMessage(config *Config, topic string, qos packet.QOS, timeout time.Duration) (*packet.Message, error) {
// create client
client := New()
// connect to broker
future, err := client.Connect(config)
if err != nil {
return nil, err
}
// wait for future
err = future.Wait(timeout)
if err != nil {
r... | [
"func",
"ReceiveMessage",
"(",
"config",
"*",
"Config",
",",
"topic",
"string",
",",
"qos",
"packet",
".",
"QOS",
",",
"timeout",
"time",
".",
"Duration",
")",
"(",
"*",
"packet",
".",
"Message",
",",
"error",
")",
"{",
"// create client",
"client",
":="... | // ReceiveMessage will connect to the specified broker and issue a subscription
// for the specified topic and return the first message received. | [
"ReceiveMessage",
"will",
"connect",
"to",
"the",
"specified",
"broker",
"and",
"issue",
"a",
"subscription",
"for",
"the",
"specified",
"topic",
"and",
"return",
"the",
"first",
"message",
"received",
"."
] | 84c68b46ee22292c5ac9c44c7678ac33ae14f130 | https://github.com/256dpi/gomqtt/blob/84c68b46ee22292c5ac9c44c7678ac33ae14f130/client/tools.go#L90-L151 |
10,081 | honeycombio/honeytail | httime/httime.go | GetTimestamp | func GetTimestamp(m map[string]interface{}, timeFieldName, timeFieldFormat string) time.Time {
var (
ts time.Time
foundFieldName string
timeFoundImproperTypeMsg = "Found time field but type is not string or int"
timeFoundInvalidFormatMsg = "found time field but failed to pars... | go | func GetTimestamp(m map[string]interface{}, timeFieldName, timeFieldFormat string) time.Time {
var (
ts time.Time
foundFieldName string
timeFoundImproperTypeMsg = "Found time field but type is not string or int"
timeFoundInvalidFormatMsg = "found time field but failed to pars... | [
"func",
"GetTimestamp",
"(",
"m",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"timeFieldName",
",",
"timeFieldFormat",
"string",
")",
"time",
".",
"Time",
"{",
"var",
"(",
"ts",
"time",
".",
"Time",
"\n",
"foundFieldName",
"string",
"\n",
"tim... | // GetTimestamp looks through the event map for something that looks like a
// timestamp.
//
// It will guess at the key name or use the specified one if it is not an empty
// string. If unable to parse the timestamp, it will return the current time.
// The time field will be deleted from the map if found. | [
"GetTimestamp",
"looks",
"through",
"the",
"event",
"map",
"for",
"something",
"that",
"looks",
"like",
"a",
"timestamp",
".",
"It",
"will",
"guess",
"at",
"the",
"key",
"name",
"or",
"use",
"the",
"specified",
"one",
"if",
"it",
"is",
"not",
"an",
"empt... | a4d169e4b0f5204538da680d276e09be979ee26c | https://github.com/honeycombio/honeytail/blob/a4d169e4b0f5204538da680d276e09be979ee26c/httime/httime.go#L114-L176 |
10,082 | honeycombio/honeytail | httime/httime.go | Parse | func Parse(format, timespec string) (time.Time, error) {
return time.ParseInLocation(format, timespec, Location)
} | go | func Parse(format, timespec string) (time.Time, error) {
return time.ParseInLocation(format, timespec, Location)
} | [
"func",
"Parse",
"(",
"format",
",",
"timespec",
"string",
")",
"(",
"time",
".",
"Time",
",",
"error",
")",
"{",
"return",
"time",
".",
"ParseInLocation",
"(",
"format",
",",
"timespec",
",",
"Location",
")",
"\n",
"}"
] | // Parse wraps time.ParseInLocation to use httime's Location from parsers | [
"Parse",
"wraps",
"time",
".",
"ParseInLocation",
"to",
"use",
"httime",
"s",
"Location",
"from",
"parsers"
] | a4d169e4b0f5204538da680d276e09be979ee26c | https://github.com/honeycombio/honeytail/blob/a4d169e4b0f5204538da680d276e09be979ee26c/httime/httime.go#L179-L181 |
10,083 | honeycombio/honeytail | httime/httime.go | convertTimeFormat | func convertTimeFormat(layout string) string {
for format, conv := range convertMapping {
layout = strings.Replace(layout, format, conv, -1)
}
return layout
} | go | func convertTimeFormat(layout string) string {
for format, conv := range convertMapping {
layout = strings.Replace(layout, format, conv, -1)
}
return layout
} | [
"func",
"convertTimeFormat",
"(",
"layout",
"string",
")",
"string",
"{",
"for",
"format",
",",
"conv",
":=",
"range",
"convertMapping",
"{",
"layout",
"=",
"strings",
".",
"Replace",
"(",
"layout",
",",
"format",
",",
"conv",
",",
"-",
"1",
")",
"\n",
... | // convertTimeFormat tries to handle C-style time formats alongside Go's
// existing time.Parse behavior. | [
"convertTimeFormat",
"tries",
"to",
"handle",
"C",
"-",
"style",
"time",
"formats",
"alongside",
"Go",
"s",
"existing",
"time",
".",
"Parse",
"behavior",
"."
] | a4d169e4b0f5204538da680d276e09be979ee26c | https://github.com/honeycombio/honeytail/blob/a4d169e4b0f5204538da680d276e09be979ee26c/httime/httime.go#L185-L190 |
10,084 | honeycombio/honeytail | parsers/postgresql/postgresql.go | handleEvents | func (p *Parser) handleEvents(rawEvents <-chan []string, send chan<- event.Event, wg *sync.WaitGroup) {
defer wg.Done()
// TODO: spin up a group of goroutines to do this
for rawEvent := range rawEvents {
ev := p.handleEvent(rawEvent)
if ev != nil {
send <- *ev
}
}
} | go | func (p *Parser) handleEvents(rawEvents <-chan []string, send chan<- event.Event, wg *sync.WaitGroup) {
defer wg.Done()
// TODO: spin up a group of goroutines to do this
for rawEvent := range rawEvents {
ev := p.handleEvent(rawEvent)
if ev != nil {
send <- *ev
}
}
} | [
"func",
"(",
"p",
"*",
"Parser",
")",
"handleEvents",
"(",
"rawEvents",
"<-",
"chan",
"[",
"]",
"string",
",",
"send",
"chan",
"<-",
"event",
".",
"Event",
",",
"wg",
"*",
"sync",
".",
"WaitGroup",
")",
"{",
"defer",
"wg",
".",
"Done",
"(",
")",
... | // handleEvents receives sets of grouped log lines, each representing a single
// log statement. It attempts to parse them, and sends the events it constructs
// down the send channel. | [
"handleEvents",
"receives",
"sets",
"of",
"grouped",
"log",
"lines",
"each",
"representing",
"a",
"single",
"log",
"statement",
".",
"It",
"attempts",
"to",
"parse",
"them",
"and",
"sends",
"the",
"events",
"it",
"constructs",
"down",
"the",
"send",
"channel",... | a4d169e4b0f5204538da680d276e09be979ee26c | https://github.com/honeycombio/honeytail/blob/a4d169e4b0f5204538da680d276e09be979ee26c/parsers/postgresql/postgresql.go#L162-L171 |
10,085 | honeycombio/honeytail | parsers/postgresql/postgresql.go | addFieldsToEvent | func addFieldsToEvent(fields map[string]string, ev *event.Event) {
for k, v := range fields {
// Try to convert values to integer types where sensible, and extract
// timestamp for event
switch k {
case "session_id", "pid", "session_line_number":
if typed, err := strconv.Atoi(v); err == nil {
ev.Data[k]... | go | func addFieldsToEvent(fields map[string]string, ev *event.Event) {
for k, v := range fields {
// Try to convert values to integer types where sensible, and extract
// timestamp for event
switch k {
case "session_id", "pid", "session_line_number":
if typed, err := strconv.Atoi(v); err == nil {
ev.Data[k]... | [
"func",
"addFieldsToEvent",
"(",
"fields",
"map",
"[",
"string",
"]",
"string",
",",
"ev",
"*",
"event",
".",
"Event",
")",
"{",
"for",
"k",
",",
"v",
":=",
"range",
"fields",
"{",
"// Try to convert values to integer types where sensible, and extract",
"// timest... | // addFieldsToEvent takes a map of key-value metadata extracted from a log
// line, and adds them to the given event. It'll convert values to integer
// types where possible, and try to populate the event's timestamp. | [
"addFieldsToEvent",
"takes",
"a",
"map",
"of",
"key",
"-",
"value",
"metadata",
"extracted",
"from",
"a",
"log",
"line",
"and",
"adds",
"them",
"to",
"the",
"given",
"event",
".",
"It",
"ll",
"convert",
"values",
"to",
"integer",
"types",
"where",
"possibl... | a4d169e4b0f5204538da680d276e09be979ee26c | https://github.com/honeycombio/honeytail/blob/a4d169e4b0f5204538da680d276e09be979ee26c/parsers/postgresql/postgresql.go#L238-L268 |
10,086 | honeycombio/honeytail | parsers/extregexp.go | FindStringSubmatchMap | func (r *ExtRegexp) FindStringSubmatchMap(s string) (string, map[string]string) {
match := r.FindStringSubmatch(s)
if match == nil {
return "", nil
}
captures := make(map[string]string)
for i, name := range r.SubexpNames() {
if i == 0 {
continue
}
if name != "" {
// ignore unnamed matches
capture... | go | func (r *ExtRegexp) FindStringSubmatchMap(s string) (string, map[string]string) {
match := r.FindStringSubmatch(s)
if match == nil {
return "", nil
}
captures := make(map[string]string)
for i, name := range r.SubexpNames() {
if i == 0 {
continue
}
if name != "" {
// ignore unnamed matches
capture... | [
"func",
"(",
"r",
"*",
"ExtRegexp",
")",
"FindStringSubmatchMap",
"(",
"s",
"string",
")",
"(",
"string",
",",
"map",
"[",
"string",
"]",
"string",
")",
"{",
"match",
":=",
"r",
".",
"FindStringSubmatch",
"(",
"s",
")",
"\n",
"if",
"match",
"==",
"ni... | // FindStringSubmatchMap behaves the same as FindStringSubmatch except instead
// of a list of matches with the names separate, it returns the full match and a
// map of named submatches | [
"FindStringSubmatchMap",
"behaves",
"the",
"same",
"as",
"FindStringSubmatch",
"except",
"instead",
"of",
"a",
"list",
"of",
"matches",
"with",
"the",
"names",
"separate",
"it",
"returns",
"the",
"full",
"match",
"and",
"a",
"map",
"of",
"named",
"submatches"
] | a4d169e4b0f5204538da680d276e09be979ee26c | https://github.com/honeycombio/honeytail/blob/a4d169e4b0f5204538da680d276e09be979ee26c/parsers/extregexp.go#L14-L31 |
10,087 | honeycombio/honeytail | leash.go | getParserAndOptions | func getParserAndOptions(options GlobalOptions) (parsers.Parser, interface{}) {
var parser parsers.Parser
var opts interface{}
switch options.Reqs.ParserName {
case "regex":
parser = ®ex.Parser{}
opts = &options.Regex
opts.(*regex.Options).NumParsers = int(options.NumSenders)
case "nginx":
parser = &ngi... | go | func getParserAndOptions(options GlobalOptions) (parsers.Parser, interface{}) {
var parser parsers.Parser
var opts interface{}
switch options.Reqs.ParserName {
case "regex":
parser = ®ex.Parser{}
opts = &options.Regex
opts.(*regex.Options).NumParsers = int(options.NumSenders)
case "nginx":
parser = &ngi... | [
"func",
"getParserAndOptions",
"(",
"options",
"GlobalOptions",
")",
"(",
"parsers",
".",
"Parser",
",",
"interface",
"{",
"}",
")",
"{",
"var",
"parser",
"parsers",
".",
"Parser",
"\n",
"var",
"opts",
"interface",
"{",
"}",
"\n",
"switch",
"options",
".",... | // getParserOptions takes a parser name and the global options struct
// it returns the options group for the specified parser | [
"getParserOptions",
"takes",
"a",
"parser",
"name",
"and",
"the",
"global",
"options",
"struct",
"it",
"returns",
"the",
"options",
"group",
"for",
"the",
"specified",
"parser"
] | a4d169e4b0f5204538da680d276e09be979ee26c | https://github.com/honeycombio/honeytail/blob/a4d169e4b0f5204538da680d276e09be979ee26c/leash.go#L208-L255 |
10,088 | honeycombio/honeytail | leash.go | makeDynsampleKey | func makeDynsampleKey(ev *event.Event, options GlobalOptions) string {
key := make([]string, len(options.DynSample))
for i, field := range options.DynSample {
if val, ok := ev.Data[field]; ok {
switch val := val.(type) {
case bool:
key[i] = strconv.FormatBool(val)
case int64:
key[i] = strconv.Forma... | go | func makeDynsampleKey(ev *event.Event, options GlobalOptions) string {
key := make([]string, len(options.DynSample))
for i, field := range options.DynSample {
if val, ok := ev.Data[field]; ok {
switch val := val.(type) {
case bool:
key[i] = strconv.FormatBool(val)
case int64:
key[i] = strconv.Forma... | [
"func",
"makeDynsampleKey",
"(",
"ev",
"*",
"event",
".",
"Event",
",",
"options",
"GlobalOptions",
")",
"string",
"{",
"key",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"options",
".",
"DynSample",
")",
")",
"\n",
"for",
"i",
",",
"fiel... | // makeDynsampleKey pulls in all the values necessary from the event to create a
// key for dynamic sampling | [
"makeDynsampleKey",
"pulls",
"in",
"all",
"the",
"values",
"necessary",
"from",
"the",
"event",
"to",
"create",
"a",
"key",
"for",
"dynamic",
"sampling"
] | a4d169e4b0f5204538da680d276e09be979ee26c | https://github.com/honeycombio/honeytail/blob/a4d169e4b0f5204538da680d276e09be979ee26c/leash.go#L457-L477 |
10,089 | honeycombio/honeytail | leash.go | whitelistKey | func whitelistKey(whiteKeys []string, key string) bool {
for _, whiteKey := range whiteKeys {
if key == whiteKey {
return true
}
}
return false
} | go | func whitelistKey(whiteKeys []string, key string) bool {
for _, whiteKey := range whiteKeys {
if key == whiteKey {
return true
}
}
return false
} | [
"func",
"whitelistKey",
"(",
"whiteKeys",
"[",
"]",
"string",
",",
"key",
"string",
")",
"bool",
"{",
"for",
"_",
",",
"whiteKey",
":=",
"range",
"whiteKeys",
"{",
"if",
"key",
"==",
"whiteKey",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"ret... | // return true if the key is in the whitelist | [
"return",
"true",
"if",
"the",
"key",
"is",
"in",
"the",
"whitelist"
] | a4d169e4b0f5204538da680d276e09be979ee26c | https://github.com/honeycombio/honeytail/blob/a4d169e4b0f5204538da680d276e09be979ee26c/leash.go#L547-L554 |
10,090 | honeycombio/honeytail | leash.go | sendToLibhoney | func sendToLibhoney(ctx context.Context, toBeSent chan event.Event, toBeResent chan event.Event,
delaySending chan int, doneSending chan bool) {
for {
// check and see if we need to back off the API because of rate limiting
select {
case delay := <-delaySending:
time.Sleep(time.Duration(delay) * time.Millise... | go | func sendToLibhoney(ctx context.Context, toBeSent chan event.Event, toBeResent chan event.Event,
delaySending chan int, doneSending chan bool) {
for {
// check and see if we need to back off the API because of rate limiting
select {
case delay := <-delaySending:
time.Sleep(time.Duration(delay) * time.Millise... | [
"func",
"sendToLibhoney",
"(",
"ctx",
"context",
".",
"Context",
",",
"toBeSent",
"chan",
"event",
".",
"Event",
",",
"toBeResent",
"chan",
"event",
".",
"Event",
",",
"delaySending",
"chan",
"int",
",",
"doneSending",
"chan",
"bool",
")",
"{",
"for",
"{",... | // sendToLibhoney reads from the toBeSent channel and shoves the events into
// libhoney events, sending them on their way. | [
"sendToLibhoney",
"reads",
"from",
"the",
"toBeSent",
"channel",
"and",
"shoves",
"the",
"events",
"into",
"libhoney",
"events",
"sending",
"them",
"on",
"their",
"way",
"."
] | a4d169e4b0f5204538da680d276e09be979ee26c | https://github.com/honeycombio/honeytail/blob/a4d169e4b0f5204538da680d276e09be979ee26c/leash.go#L558-L592 |
10,091 | honeycombio/honeytail | leash.go | sendEvent | func sendEvent(ev event.Event) {
if ev.SampleRate == -1 {
// drop the event!
logrus.WithFields(logrus.Fields{
"event": ev,
}).Debug("droppped event due to sampling")
return
}
libhEv := libhoney.NewEvent()
libhEv.Metadata = ev
libhEv.Timestamp = ev.Timestamp
libhEv.SampleRate = uint(ev.SampleRate)
if e... | go | func sendEvent(ev event.Event) {
if ev.SampleRate == -1 {
// drop the event!
logrus.WithFields(logrus.Fields{
"event": ev,
}).Debug("droppped event due to sampling")
return
}
libhEv := libhoney.NewEvent()
libhEv.Metadata = ev
libhEv.Timestamp = ev.Timestamp
libhEv.SampleRate = uint(ev.SampleRate)
if e... | [
"func",
"sendEvent",
"(",
"ev",
"event",
".",
"Event",
")",
"{",
"if",
"ev",
".",
"SampleRate",
"==",
"-",
"1",
"{",
"// drop the event!",
"logrus",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"\"",
"\"",
":",
"ev",
",",
"}",
")",
".",
"D... | // sendEvent does the actual handoff to libhoney | [
"sendEvent",
"does",
"the",
"actual",
"handoff",
"to",
"libhoney"
] | a4d169e4b0f5204538da680d276e09be979ee26c | https://github.com/honeycombio/honeytail/blob/a4d169e4b0f5204538da680d276e09be979ee26c/leash.go#L595-L619 |
10,092 | honeycombio/honeytail | leash.go | handleResponses | func handleResponses(responses chan libhoney.Response, stats *responseStats,
toBeResent chan event.Event, delaySending chan int,
options GlobalOptions) {
go logStats(stats, options.StatusInterval)
for rsp := range responses {
stats.update(rsp)
logfields := logrus.Fields{
"status_code": rsp.StatusCode,
"b... | go | func handleResponses(responses chan libhoney.Response, stats *responseStats,
toBeResent chan event.Event, delaySending chan int,
options GlobalOptions) {
go logStats(stats, options.StatusInterval)
for rsp := range responses {
stats.update(rsp)
logfields := logrus.Fields{
"status_code": rsp.StatusCode,
"b... | [
"func",
"handleResponses",
"(",
"responses",
"chan",
"libhoney",
".",
"Response",
",",
"stats",
"*",
"responseStats",
",",
"toBeResent",
"chan",
"event",
".",
"Event",
",",
"delaySending",
"chan",
"int",
",",
"options",
"GlobalOptions",
")",
"{",
"go",
"logSta... | // handleResponses reads from the response queue, logging a summary and debug
// re-enqueues any events that failed to send in a retryable way | [
"handleResponses",
"reads",
"from",
"the",
"response",
"queue",
"logging",
"a",
"summary",
"and",
"debug",
"re",
"-",
"enqueues",
"any",
"events",
"that",
"failed",
"to",
"send",
"in",
"a",
"retryable",
"way"
] | a4d169e4b0f5204538da680d276e09be979ee26c | https://github.com/honeycombio/honeytail/blob/a4d169e4b0f5204538da680d276e09be979ee26c/leash.go#L623-L647 |
10,093 | honeycombio/honeytail | leash.go | logStats | func logStats(stats *responseStats, interval uint) {
logrus.Debugf("Initializing stats reporting. Will print stats once/%d seconds", interval)
if interval == 0 {
// interval of 0 means don't print summary status
return
}
ticker := time.NewTicker(time.Second * time.Duration(interval))
for range ticker.C {
sta... | go | func logStats(stats *responseStats, interval uint) {
logrus.Debugf("Initializing stats reporting. Will print stats once/%d seconds", interval)
if interval == 0 {
// interval of 0 means don't print summary status
return
}
ticker := time.NewTicker(time.Second * time.Duration(interval))
for range ticker.C {
sta... | [
"func",
"logStats",
"(",
"stats",
"*",
"responseStats",
",",
"interval",
"uint",
")",
"{",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"interval",
")",
"\n",
"if",
"interval",
"==",
"0",
"{",
"// interval of 0 means don't print summary status",
"return",
"\... | // logStats dumps and resets the stats once every minute | [
"logStats",
"dumps",
"and",
"resets",
"the",
"stats",
"once",
"every",
"minute"
] | a4d169e4b0f5204538da680d276e09be979ee26c | https://github.com/honeycombio/honeytail/blob/a4d169e4b0f5204538da680d276e09be979ee26c/leash.go#L650-L660 |
10,094 | honeycombio/honeytail | parsers/nginx/nginx.go | typeifyParsedLine | func typeifyParsedLine(pl map[string]string) map[string]interface{} {
// try to convert numbers, if possible
msi := make(map[string]interface{}, len(pl))
for k, v := range pl {
switch {
case strings.Contains(v, "."):
f, err := strconv.ParseFloat(v, 64)
if err == nil {
msi[k] = f
continue
}
cas... | go | func typeifyParsedLine(pl map[string]string) map[string]interface{} {
// try to convert numbers, if possible
msi := make(map[string]interface{}, len(pl))
for k, v := range pl {
switch {
case strings.Contains(v, "."):
f, err := strconv.ParseFloat(v, 64)
if err == nil {
msi[k] = f
continue
}
cas... | [
"func",
"typeifyParsedLine",
"(",
"pl",
"map",
"[",
"string",
"]",
"string",
")",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"// try to convert numbers, if possible",
"msi",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"... | // typeifyParsedLine attempts to cast numbers in the event to floats or ints | [
"typeifyParsedLine",
"attempts",
"to",
"cast",
"numbers",
"in",
"the",
"event",
"to",
"floats",
"or",
"ints"
] | a4d169e4b0f5204538da680d276e09be979ee26c | https://github.com/honeycombio/honeytail/blob/a4d169e4b0f5204538da680d276e09be979ee26c/parsers/nginx/nginx.go#L127-L151 |
10,095 | honeycombio/honeytail | parsers/nginx/nginx.go | getTimestamp | func (n *Parser) getTimestamp(evMap map[string]interface{}) time.Time {
var (
setBothFieldsMsg = "Timestamp format and field must both be set to be used, one was not. Using current time instead."
)
// Custom (user-defined) timestamp field/format takes priority over the
// default parsing behavior. Try that first... | go | func (n *Parser) getTimestamp(evMap map[string]interface{}) time.Time {
var (
setBothFieldsMsg = "Timestamp format and field must both be set to be used, one was not. Using current time instead."
)
// Custom (user-defined) timestamp field/format takes priority over the
// default parsing behavior. Try that first... | [
"func",
"(",
"n",
"*",
"Parser",
")",
"getTimestamp",
"(",
"evMap",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"time",
".",
"Time",
"{",
"var",
"(",
"setBothFieldsMsg",
"=",
"\"",
"\"",
"\n",
")",
"\n\n",
"// Custom (user-defined) timestamp fie... | // tries to extract a timestamp from the log line | [
"tries",
"to",
"extract",
"a",
"timestamp",
"from",
"the",
"log",
"line"
] | a4d169e4b0f5204538da680d276e09be979ee26c | https://github.com/honeycombio/honeytail/blob/a4d169e4b0f5204538da680d276e09be979ee26c/parsers/nginx/nginx.go#L154-L182 |
10,096 | honeycombio/honeytail | tail/tail.go | GetSampledEntries | func GetSampledEntries(ctx context.Context, conf Config, sampleRate uint) ([]chan string, error) {
unsampledLinesChans, err := GetEntries(ctx, conf)
if err != nil {
return nil, err
}
if sampleRate == 1 {
return unsampledLinesChans, nil
}
sampledLinesChans := make([]chan string, 0, len(unsampledLinesChans))
... | go | func GetSampledEntries(ctx context.Context, conf Config, sampleRate uint) ([]chan string, error) {
unsampledLinesChans, err := GetEntries(ctx, conf)
if err != nil {
return nil, err
}
if sampleRate == 1 {
return unsampledLinesChans, nil
}
sampledLinesChans := make([]chan string, 0, len(unsampledLinesChans))
... | [
"func",
"GetSampledEntries",
"(",
"ctx",
"context",
".",
"Context",
",",
"conf",
"Config",
",",
"sampleRate",
"uint",
")",
"(",
"[",
"]",
"chan",
"string",
",",
"error",
")",
"{",
"unsampledLinesChans",
",",
"err",
":=",
"GetEntries",
"(",
"ctx",
",",
"c... | // GetSampledEntries wraps GetEntries and returns a list of channels that
// provide sampled entries | [
"GetSampledEntries",
"wraps",
"GetEntries",
"and",
"returns",
"a",
"list",
"of",
"channels",
"that",
"provide",
"sampled",
"entries"
] | a4d169e4b0f5204538da680d276e09be979ee26c | https://github.com/honeycombio/honeytail/blob/a4d169e4b0f5204538da680d276e09be979ee26c/tail/tail.go#L68-L97 |
10,097 | honeycombio/honeytail | tail/tail.go | GetEntries | func GetEntries(ctx context.Context, conf Config) ([]chan string, error) {
if conf.Type != RotateStyleSyslog {
return nil, errors.New("Only Syslog style rotation currently supported")
}
// expand any globs in the list of files so our list all represents real files
var filenames []string
for _, filePath := range ... | go | func GetEntries(ctx context.Context, conf Config) ([]chan string, error) {
if conf.Type != RotateStyleSyslog {
return nil, errors.New("Only Syslog style rotation currently supported")
}
// expand any globs in the list of files so our list all represents real files
var filenames []string
for _, filePath := range ... | [
"func",
"GetEntries",
"(",
"ctx",
"context",
".",
"Context",
",",
"conf",
"Config",
")",
"(",
"[",
"]",
"chan",
"string",
",",
"error",
")",
"{",
"if",
"conf",
".",
"Type",
"!=",
"RotateStyleSyslog",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"... | // GetEntries sets up a list of channels that get one line at a time from each
// file down each channel. | [
"GetEntries",
"sets",
"up",
"a",
"list",
"of",
"channels",
"that",
"get",
"one",
"line",
"at",
"a",
"time",
"from",
"each",
"file",
"down",
"each",
"channel",
"."
] | a4d169e4b0f5204538da680d276e09be979ee26c | https://github.com/honeycombio/honeytail/blob/a4d169e4b0f5204538da680d276e09be979ee26c/tail/tail.go#L109-L151 |
10,098 | honeycombio/honeytail | tail/tail.go | removeStateFiles | func removeStateFiles(files []string, conf Config) []string {
newFiles := []string{}
for _, file := range files {
if file == conf.Options.StateFile {
logrus.WithFields(logrus.Fields{
"file": file,
}).Debug("skipping tailing file because it is named the same as the statefile flag")
continue
}
if str... | go | func removeStateFiles(files []string, conf Config) []string {
newFiles := []string{}
for _, file := range files {
if file == conf.Options.StateFile {
logrus.WithFields(logrus.Fields{
"file": file,
}).Debug("skipping tailing file because it is named the same as the statefile flag")
continue
}
if str... | [
"func",
"removeStateFiles",
"(",
"files",
"[",
"]",
"string",
",",
"conf",
"Config",
")",
"[",
"]",
"string",
"{",
"newFiles",
":=",
"[",
"]",
"string",
"{",
"}",
"\n",
"for",
"_",
",",
"file",
":=",
"range",
"files",
"{",
"if",
"file",
"==",
"conf... | // removeStateFiles goes through the list of files and removes any that appear
// to be statefiles to avoid .leash.state.leash.state.leash.state from appearing
// when you use an overly permissive glob | [
"removeStateFiles",
"goes",
"through",
"the",
"list",
"of",
"files",
"and",
"removes",
"any",
"that",
"appear",
"to",
"be",
"statefiles",
"to",
"avoid",
".",
"leash",
".",
"state",
".",
"leash",
".",
"state",
".",
"leash",
".",
"state",
"from",
"appearing"... | a4d169e4b0f5204538da680d276e09be979ee26c | https://github.com/honeycombio/honeytail/blob/a4d169e4b0f5204538da680d276e09be979ee26c/tail/tail.go#L156-L175 |
10,099 | honeycombio/honeytail | tail/tail.go | tailStdIn | func tailStdIn(ctx context.Context) chan string {
lines := make(chan string)
input := bufio.NewReader(os.Stdin)
go func() {
defer close(lines)
for {
// check for signal triggered exit
select {
case <-ctx.Done():
return
default:
}
line, partialLine, err := input.ReadLine()
if err != nil {... | go | func tailStdIn(ctx context.Context) chan string {
lines := make(chan string)
input := bufio.NewReader(os.Stdin)
go func() {
defer close(lines)
for {
// check for signal triggered exit
select {
case <-ctx.Done():
return
default:
}
line, partialLine, err := input.ReadLine()
if err != nil {... | [
"func",
"tailStdIn",
"(",
"ctx",
"context",
".",
"Context",
")",
"chan",
"string",
"{",
"lines",
":=",
"make",
"(",
"chan",
"string",
")",
"\n",
"input",
":=",
"bufio",
".",
"NewReader",
"(",
"os",
".",
"Stdin",
")",
"\n",
"go",
"func",
"(",
")",
"... | // tailStdIn is a special case to tail STDIN without any of the
// fancy stuff that the tail module provides | [
"tailStdIn",
"is",
"a",
"special",
"case",
"to",
"tail",
"STDIN",
"without",
"any",
"of",
"the",
"fancy",
"stuff",
"that",
"the",
"tail",
"module",
"provides"
] | a4d169e4b0f5204538da680d276e09be979ee26c | https://github.com/honeycombio/honeytail/blob/a4d169e4b0f5204538da680d276e09be979ee26c/tail/tail.go#L257-L285 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.