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
164,300
asticode/go-astilectron
dock.go
Show
func (d *Dock) Show() (err error) { if err = d.isActionable(); err != nil { return } _, err = synchronousEvent(d.c, d, d.w, Event{Name: eventNameDockCmdShow, TargetID: d.id}, eventNameDockEventShown) return }
go
func (d *Dock) Show() (err error) { if err = d.isActionable(); err != nil { return } _, err = synchronousEvent(d.c, d, d.w, Event{Name: eventNameDockCmdShow, TargetID: d.id}, eventNameDockEventShown) return }
[ "func", "(", "d", "*", "Dock", ")", "Show", "(", ")", "(", "err", "error", ")", "{", "if", "err", "=", "d", ".", "isActionable", "(", ")", ";", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "_", ",", "err", "=", "synchronousEvent", "(", ...
// Show shows the dock
[ "Show", "shows", "the", "dock" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/dock.go#L105-L111
164,301
asticode/go-astilectron
helper.go
Disembed
func Disembed(ctx context.Context, d Disembedder, src, dst string) (err error) { // Log astilog.Debugf("Disembedding %s into %s...", src, dst) // No need to disembed if _, err = os.Stat(dst); err != nil && !os.IsNotExist(err) { return errors.Wrapf(err, "stating %s failed", dst) } else if err == nil { astilog.Debugf("%s already exists, skipping disembed...", dst) return } err = nil // Clean up on error defer func(err *error) { if *err != nil || ctx.Err() != nil { astilog.Debugf("Removing %s...", dst) os.Remove(dst) } }(&err) // Make sure directory exists var dirPath = filepath.Dir(dst) astilog.Debugf("Creating %s", dirPath) if err = os.MkdirAll(dirPath, 0755); err != nil { return errors.Wrapf(err, "mkdirall %s failed", dirPath) } // Create dst var f *os.File astilog.Debugf("Creating %s", dst) if f, err = os.Create(dst); err != nil { return errors.Wrapf(err, "creating %s failed", dst) } defer f.Close() // Disembed var b []byte astilog.Debugf("Disembedding %s", src) if b, err = d(src); err != nil { return errors.Wrapf(err, "disembedding %s failed", src) } // Copy astilog.Debugf("Copying disembedded data to %s", dst) if _, err = astiio.Copy(ctx, bytes.NewReader(b), f); err != nil { return errors.Wrapf(err, "copying disembedded data into %s failed", dst) } return }
go
func Disembed(ctx context.Context, d Disembedder, src, dst string) (err error) { // Log astilog.Debugf("Disembedding %s into %s...", src, dst) // No need to disembed if _, err = os.Stat(dst); err != nil && !os.IsNotExist(err) { return errors.Wrapf(err, "stating %s failed", dst) } else if err == nil { astilog.Debugf("%s already exists, skipping disembed...", dst) return } err = nil // Clean up on error defer func(err *error) { if *err != nil || ctx.Err() != nil { astilog.Debugf("Removing %s...", dst) os.Remove(dst) } }(&err) // Make sure directory exists var dirPath = filepath.Dir(dst) astilog.Debugf("Creating %s", dirPath) if err = os.MkdirAll(dirPath, 0755); err != nil { return errors.Wrapf(err, "mkdirall %s failed", dirPath) } // Create dst var f *os.File astilog.Debugf("Creating %s", dst) if f, err = os.Create(dst); err != nil { return errors.Wrapf(err, "creating %s failed", dst) } defer f.Close() // Disembed var b []byte astilog.Debugf("Disembedding %s", src) if b, err = d(src); err != nil { return errors.Wrapf(err, "disembedding %s failed", src) } // Copy astilog.Debugf("Copying disembedded data to %s", dst) if _, err = astiio.Copy(ctx, bytes.NewReader(b), f); err != nil { return errors.Wrapf(err, "copying disembedded data into %s failed", dst) } return }
[ "func", "Disembed", "(", "ctx", "context", ".", "Context", ",", "d", "Disembedder", ",", "src", ",", "dst", "string", ")", "(", "err", "error", ")", "{", "// Log", "astilog", ".", "Debugf", "(", "\"", "\"", ",", "src", ",", "dst", ")", "\n\n", "// ...
// Disembed is a cancellable disembed of an src to a dst using a custom Disembedder
[ "Disembed", "is", "a", "cancellable", "disembed", "of", "an", "src", "to", "a", "dst", "using", "a", "custom", "Disembedder" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/helper.go#L54-L103
164,302
asticode/go-astilectron
helper.go
synchronousFunc
func synchronousFunc(c *asticontext.Canceller, l listenable, fn func(), eventNameDone string) (e Event) { var ctx, cancel = c.NewContext() defer cancel() l.On(eventNameDone, func(i Event) (deleteListener bool) { e = i cancel() return true }) fn() <-ctx.Done() return }
go
func synchronousFunc(c *asticontext.Canceller, l listenable, fn func(), eventNameDone string) (e Event) { var ctx, cancel = c.NewContext() defer cancel() l.On(eventNameDone, func(i Event) (deleteListener bool) { e = i cancel() return true }) fn() <-ctx.Done() return }
[ "func", "synchronousFunc", "(", "c", "*", "asticontext", ".", "Canceller", ",", "l", "listenable", ",", "fn", "func", "(", ")", ",", "eventNameDone", "string", ")", "(", "e", "Event", ")", "{", "var", "ctx", ",", "cancel", "=", "c", ".", "NewContext", ...
// synchronousFunc executes a function, blocks until it has received a specific event or the canceller has been // cancelled and returns the corresponding event
[ "synchronousFunc", "executes", "a", "function", "blocks", "until", "it", "has", "received", "a", "specific", "event", "or", "the", "canceller", "has", "been", "cancelled", "and", "returns", "the", "corresponding", "event" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/helper.go#L152-L163
164,303
asticode/go-astilectron
helper.go
synchronousEvent
func synchronousEvent(c *asticontext.Canceller, l listenable, w *writer, i Event, eventNameDone string) (o Event, err error) { o = synchronousFunc(c, l, func() { if err = w.write(i); err != nil { err = errors.Wrapf(err, "writing %+v event failed", i) return } return }, eventNameDone) return }
go
func synchronousEvent(c *asticontext.Canceller, l listenable, w *writer, i Event, eventNameDone string) (o Event, err error) { o = synchronousFunc(c, l, func() { if err = w.write(i); err != nil { err = errors.Wrapf(err, "writing %+v event failed", i) return } return }, eventNameDone) return }
[ "func", "synchronousEvent", "(", "c", "*", "asticontext", ".", "Canceller", ",", "l", "listenable", ",", "w", "*", "writer", ",", "i", "Event", ",", "eventNameDone", "string", ")", "(", "o", "Event", ",", "err", "error", ")", "{", "o", "=", "synchronou...
// synchronousEvent sends an event, blocks until it has received a specific event or the canceller has been cancelled // and returns the corresponding event
[ "synchronousEvent", "sends", "an", "event", "blocks", "until", "it", "has", "received", "a", "specific", "event", "or", "the", "canceller", "has", "been", "cancelled", "and", "returns", "the", "corresponding", "event" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/helper.go#L167-L176
164,304
asticode/go-astilectron
identifier.go
new
func (i *identifier) new() string { i.m.Lock() defer i.m.Unlock() i.i++ return strconv.Itoa(i.i) }
go
func (i *identifier) new() string { i.m.Lock() defer i.m.Unlock() i.i++ return strconv.Itoa(i.i) }
[ "func", "(", "i", "*", "identifier", ")", "new", "(", ")", "string", "{", "i", ".", "m", ".", "Lock", "(", ")", "\n", "defer", "i", ".", "m", ".", "Unlock", "(", ")", "\n", "i", ".", "i", "++", "\n", "return", "strconv", ".", "Itoa", "(", "...
// new returns a new unique identifier
[ "new", "returns", "a", "new", "unique", "identifier" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/identifier.go#L20-L25
164,305
asticode/go-astilectron
reader.go
newReader
func newReader(ctx context.Context, d *dispatcher, r io.ReadCloser) *reader { return &reader{ ctx: ctx, d: d, r: r, } }
go
func newReader(ctx context.Context, d *dispatcher, r io.ReadCloser) *reader { return &reader{ ctx: ctx, d: d, r: r, } }
[ "func", "newReader", "(", "ctx", "context", ".", "Context", ",", "d", "*", "dispatcher", ",", "r", "io", ".", "ReadCloser", ")", "*", "reader", "{", "return", "&", "reader", "{", "ctx", ":", "ctx", ",", "d", ":", "d", ",", "r", ":", "r", ",", "...
// newReader creates a new reader
[ "newReader", "creates", "a", "new", "reader" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/reader.go#L22-L28
164,306
asticode/go-astilectron
reader.go
isEOFErr
func (r *reader) isEOFErr(err error) bool { return err == io.EOF || strings.Contains(strings.ToLower(err.Error()), "wsarecv:") }
go
func (r *reader) isEOFErr(err error) bool { return err == io.EOF || strings.Contains(strings.ToLower(err.Error()), "wsarecv:") }
[ "func", "(", "r", "*", "reader", ")", "isEOFErr", "(", "err", "error", ")", "bool", "{", "return", "err", "==", "io", ".", "EOF", "||", "strings", ".", "Contains", "(", "strings", ".", "ToLower", "(", "err", ".", "Error", "(", ")", ")", ",", "\""...
// isEOFErr checks whether the error is an EOF error // wsarecv is the error sent on Windows when the client closes its connection
[ "isEOFErr", "checks", "whether", "the", "error", "is", "an", "EOF", "error", "wsarecv", "is", "the", "error", "sent", "on", "Windows", "when", "the", "client", "closes", "its", "connection" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/reader.go#L37-L39
164,307
asticode/go-astilectron
reader.go
read
func (r *reader) read() { var reader = bufio.NewReader(r.r) for { // Check context error if r.ctx.Err() != nil { return } // Read next line var b []byte var err error if b, err = reader.ReadBytes('\n'); err != nil { if !r.isEOFErr(err) { astilog.Errorf("%s while reading", err) continue } return } b = bytes.TrimSpace(b) astilog.Debugf("Astilectron says: %s", b) // Unmarshal var e Event if err = json.Unmarshal(b, &e); err != nil { astilog.Errorf("%s while unmarshaling %s", err, b) continue } // Dispatch r.d.dispatch(e) } }
go
func (r *reader) read() { var reader = bufio.NewReader(r.r) for { // Check context error if r.ctx.Err() != nil { return } // Read next line var b []byte var err error if b, err = reader.ReadBytes('\n'); err != nil { if !r.isEOFErr(err) { astilog.Errorf("%s while reading", err) continue } return } b = bytes.TrimSpace(b) astilog.Debugf("Astilectron says: %s", b) // Unmarshal var e Event if err = json.Unmarshal(b, &e); err != nil { astilog.Errorf("%s while unmarshaling %s", err, b) continue } // Dispatch r.d.dispatch(e) } }
[ "func", "(", "r", "*", "reader", ")", "read", "(", ")", "{", "var", "reader", "=", "bufio", ".", "NewReader", "(", "r", ".", "r", ")", "\n", "for", "{", "// Check context error", "if", "r", ".", "ctx", ".", "Err", "(", ")", "!=", "nil", "{", "r...
// read reads from stdout
[ "read", "reads", "from", "stdout" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/reader.go#L42-L73
164,308
asticode/go-astilectron
dispatcher.go
addListener
func (d *dispatcher) addListener(targetID, eventName string, l Listener) { d.m.Lock() defer d.m.Unlock() if _, ok := d.l[targetID]; !ok { d.l[targetID] = make(map[string]map[int]Listener) } if _, ok := d.l[targetID][eventName]; !ok { d.l[targetID][eventName] = make(map[int]Listener) } d.id++ d.l[targetID][eventName][d.id] = l }
go
func (d *dispatcher) addListener(targetID, eventName string, l Listener) { d.m.Lock() defer d.m.Unlock() if _, ok := d.l[targetID]; !ok { d.l[targetID] = make(map[string]map[int]Listener) } if _, ok := d.l[targetID][eventName]; !ok { d.l[targetID][eventName] = make(map[int]Listener) } d.id++ d.l[targetID][eventName][d.id] = l }
[ "func", "(", "d", "*", "dispatcher", ")", "addListener", "(", "targetID", ",", "eventName", "string", ",", "l", "Listener", ")", "{", "d", ".", "m", ".", "Lock", "(", ")", "\n", "defer", "d", ".", "m", ".", "Unlock", "(", ")", "\n", "if", "_", ...
// addListener adds a listener
[ "addListener", "adds", "a", "listener" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/dispatcher.go#L31-L42
164,309
asticode/go-astilectron
dispatcher.go
delListener
func (d *dispatcher) delListener(targetID, eventName string, id int) { d.m.Lock() defer d.m.Unlock() if _, ok := d.l[targetID]; !ok { return } if _, ok := d.l[targetID][eventName]; !ok { return } delete(d.l[targetID][eventName], id) }
go
func (d *dispatcher) delListener(targetID, eventName string, id int) { d.m.Lock() defer d.m.Unlock() if _, ok := d.l[targetID]; !ok { return } if _, ok := d.l[targetID][eventName]; !ok { return } delete(d.l[targetID][eventName], id) }
[ "func", "(", "d", "*", "dispatcher", ")", "delListener", "(", "targetID", ",", "eventName", "string", ",", "id", "int", ")", "{", "d", ".", "m", ".", "Lock", "(", ")", "\n", "defer", "d", ".", "m", ".", "Unlock", "(", ")", "\n", "if", "_", ",",...
// delListener delete a specific listener
[ "delListener", "delete", "a", "specific", "listener" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/dispatcher.go#L45-L55
164,310
asticode/go-astilectron
dispatcher.go
dispatch
func (d *dispatcher) dispatch(e Event) { // needed so dispatches of events triggered in the listeners can be received without blocking go func() { for id, l := range d.listeners(e.TargetID, e.Name) { if l(e) { d.delListener(e.TargetID, e.Name, id) } } }() }
go
func (d *dispatcher) dispatch(e Event) { // needed so dispatches of events triggered in the listeners can be received without blocking go func() { for id, l := range d.listeners(e.TargetID, e.Name) { if l(e) { d.delListener(e.TargetID, e.Name, id) } } }() }
[ "func", "(", "d", "*", "dispatcher", ")", "dispatch", "(", "e", "Event", ")", "{", "// needed so dispatches of events triggered in the listeners can be received without blocking", "go", "func", "(", ")", "{", "for", "id", ",", "l", ":=", "range", "d", ".", "listen...
// Dispatch dispatches an event
[ "Dispatch", "dispatches", "an", "event" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/dispatcher.go#L58-L67
164,311
asticode/go-astilectron
dispatcher.go
listeners
func (d *dispatcher) listeners(targetID, eventName string) (l map[int]Listener) { d.m.Lock() defer d.m.Unlock() l = map[int]Listener{} if _, ok := d.l[targetID]; !ok { return } if _, ok := d.l[targetID][eventName]; !ok { return } for k, v := range d.l[targetID][eventName] { l[k] = v } return }
go
func (d *dispatcher) listeners(targetID, eventName string) (l map[int]Listener) { d.m.Lock() defer d.m.Unlock() l = map[int]Listener{} if _, ok := d.l[targetID]; !ok { return } if _, ok := d.l[targetID][eventName]; !ok { return } for k, v := range d.l[targetID][eventName] { l[k] = v } return }
[ "func", "(", "d", "*", "dispatcher", ")", "listeners", "(", "targetID", ",", "eventName", "string", ")", "(", "l", "map", "[", "int", "]", "Listener", ")", "{", "d", ".", "m", ".", "Lock", "(", ")", "\n", "defer", "d", ".", "m", ".", "Unlock", ...
// listeners returns the listeners for a target ID and an event name
[ "listeners", "returns", "the", "listeners", "for", "a", "target", "ID", "and", "an", "event", "name" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/dispatcher.go#L70-L84
164,312
asticode/go-astilectron
menu_item.go
newMenuItem
func newMenuItem(parentCtx context.Context, rootID string, o *MenuItemOptions, c *asticontext.Canceller, d *dispatcher, i *identifier, w *writer) (m *MenuItem) { m = &MenuItem{ o: o, object: newObject(parentCtx, c, d, i, w, i.new()), rootID: rootID, } if o.OnClick != nil { m.On(EventNameMenuItemEventClicked, o.OnClick) } if len(o.SubMenu) > 0 { m.s = &SubMenu{newSubMenu(parentCtx, rootID, o.SubMenu, c, d, i, w)} } return }
go
func newMenuItem(parentCtx context.Context, rootID string, o *MenuItemOptions, c *asticontext.Canceller, d *dispatcher, i *identifier, w *writer) (m *MenuItem) { m = &MenuItem{ o: o, object: newObject(parentCtx, c, d, i, w, i.new()), rootID: rootID, } if o.OnClick != nil { m.On(EventNameMenuItemEventClicked, o.OnClick) } if len(o.SubMenu) > 0 { m.s = &SubMenu{newSubMenu(parentCtx, rootID, o.SubMenu, c, d, i, w)} } return }
[ "func", "newMenuItem", "(", "parentCtx", "context", ".", "Context", ",", "rootID", "string", ",", "o", "*", "MenuItemOptions", ",", "c", "*", "asticontext", ".", "Canceller", ",", "d", "*", "dispatcher", ",", "i", "*", "identifier", ",", "w", "*", "write...
// newMenu creates a new menu item
[ "newMenu", "creates", "a", "new", "menu", "item" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/menu_item.go#L97-L110
164,313
asticode/go-astilectron
menu_item.go
toEvent
func (i *MenuItem) toEvent() (e *EventMenuItem) { e = &EventMenuItem{ ID: i.id, Options: i.o, RootID: i.rootID, } if i.s != nil { e.SubMenu = i.s.toEvent() } return }
go
func (i *MenuItem) toEvent() (e *EventMenuItem) { e = &EventMenuItem{ ID: i.id, Options: i.o, RootID: i.rootID, } if i.s != nil { e.SubMenu = i.s.toEvent() } return }
[ "func", "(", "i", "*", "MenuItem", ")", "toEvent", "(", ")", "(", "e", "*", "EventMenuItem", ")", "{", "e", "=", "&", "EventMenuItem", "{", "ID", ":", "i", ".", "id", ",", "Options", ":", "i", ".", "o", ",", "RootID", ":", "i", ".", "rootID", ...
// toEvent returns the menu item in the proper event format
[ "toEvent", "returns", "the", "menu", "item", "in", "the", "proper", "event", "format" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/menu_item.go#L113-L123
164,314
asticode/go-astilectron
menu_item.go
SetChecked
func (i *MenuItem) SetChecked(checked bool) (err error) { if err = i.isActionable(); err != nil { return } i.o.Checked = PtrBool(checked) _, err = synchronousEvent(i.c, i, i.w, Event{Name: EventNameMenuItemCmdSetChecked, TargetID: i.id, MenuItemOptions: &MenuItemOptions{Checked: i.o.Checked}}, EventNameMenuItemEventCheckedSet) return }
go
func (i *MenuItem) SetChecked(checked bool) (err error) { if err = i.isActionable(); err != nil { return } i.o.Checked = PtrBool(checked) _, err = synchronousEvent(i.c, i, i.w, Event{Name: EventNameMenuItemCmdSetChecked, TargetID: i.id, MenuItemOptions: &MenuItemOptions{Checked: i.o.Checked}}, EventNameMenuItemEventCheckedSet) return }
[ "func", "(", "i", "*", "MenuItem", ")", "SetChecked", "(", "checked", "bool", ")", "(", "err", "error", ")", "{", "if", "err", "=", "i", ".", "isActionable", "(", ")", ";", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "i", ".", "o", ".",...
// SetChecked sets the checked attribute
[ "SetChecked", "sets", "the", "checked", "attribute" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/menu_item.go#L131-L138
164,315
asticode/go-astilectron
menu_item.go
SetEnabled
func (i *MenuItem) SetEnabled(enabled bool) (err error) { if err = i.isActionable(); err != nil { return } i.o.Enabled = PtrBool(enabled) _, err = synchronousEvent(i.c, i, i.w, Event{Name: EventNameMenuItemCmdSetEnabled, TargetID: i.id, MenuItemOptions: &MenuItemOptions{Enabled: i.o.Enabled}}, EventNameMenuItemEventEnabledSet) return }
go
func (i *MenuItem) SetEnabled(enabled bool) (err error) { if err = i.isActionable(); err != nil { return } i.o.Enabled = PtrBool(enabled) _, err = synchronousEvent(i.c, i, i.w, Event{Name: EventNameMenuItemCmdSetEnabled, TargetID: i.id, MenuItemOptions: &MenuItemOptions{Enabled: i.o.Enabled}}, EventNameMenuItemEventEnabledSet) return }
[ "func", "(", "i", "*", "MenuItem", ")", "SetEnabled", "(", "enabled", "bool", ")", "(", "err", "error", ")", "{", "if", "err", "=", "i", ".", "isActionable", "(", ")", ";", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "i", ".", "o", ".",...
// SetEnabled sets the enabled attribute
[ "SetEnabled", "sets", "the", "enabled", "attribute" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/menu_item.go#L141-L148
164,316
asticode/go-astilectron
menu_item.go
SetLabel
func (i *MenuItem) SetLabel(label string) (err error) { if err = i.isActionable(); err != nil { return } i.o.Label = PtrStr(label) _, err = synchronousEvent(i.c, i, i.w, Event{Name: EventNameMenuItemCmdSetLabel, TargetID: i.id, MenuItemOptions: &MenuItemOptions{Label: i.o.Label}}, EventNameMenuItemEventLabelSet) return }
go
func (i *MenuItem) SetLabel(label string) (err error) { if err = i.isActionable(); err != nil { return } i.o.Label = PtrStr(label) _, err = synchronousEvent(i.c, i, i.w, Event{Name: EventNameMenuItemCmdSetLabel, TargetID: i.id, MenuItemOptions: &MenuItemOptions{Label: i.o.Label}}, EventNameMenuItemEventLabelSet) return }
[ "func", "(", "i", "*", "MenuItem", ")", "SetLabel", "(", "label", "string", ")", "(", "err", "error", ")", "{", "if", "err", "=", "i", ".", "isActionable", "(", ")", ";", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "i", ".", "o", ".", ...
// SetLabel sets the label attribute
[ "SetLabel", "sets", "the", "label", "attribute" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/menu_item.go#L151-L158
164,317
asticode/go-astilectron
menu_item.go
SetVisible
func (i *MenuItem) SetVisible(visible bool) (err error) { if err = i.isActionable(); err != nil { return } i.o.Visible = PtrBool(visible) _, err = synchronousEvent(i.c, i, i.w, Event{Name: EventNameMenuItemCmdSetVisible, TargetID: i.id, MenuItemOptions: &MenuItemOptions{Visible: i.o.Visible}}, EventNameMenuItemEventVisibleSet) return }
go
func (i *MenuItem) SetVisible(visible bool) (err error) { if err = i.isActionable(); err != nil { return } i.o.Visible = PtrBool(visible) _, err = synchronousEvent(i.c, i, i.w, Event{Name: EventNameMenuItemCmdSetVisible, TargetID: i.id, MenuItemOptions: &MenuItemOptions{Visible: i.o.Visible}}, EventNameMenuItemEventVisibleSet) return }
[ "func", "(", "i", "*", "MenuItem", ")", "SetVisible", "(", "visible", "bool", ")", "(", "err", "error", ")", "{", "if", "err", "=", "i", ".", "isActionable", "(", ")", ";", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "i", ".", "o", ".",...
// SetVisible sets the visible attribute
[ "SetVisible", "sets", "the", "visible", "attribute" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/menu_item.go#L161-L168
164,318
asticode/go-astilectron
display.go
Bounds
func (d Display) Bounds() Rectangle { return Rectangle{ Position: Position{X: *d.o.Bounds.X, Y: *d.o.Bounds.Y}, Size: Size{Height: *d.o.Bounds.Height, Width: *d.o.Bounds.Width}, } }
go
func (d Display) Bounds() Rectangle { return Rectangle{ Position: Position{X: *d.o.Bounds.X, Y: *d.o.Bounds.Y}, Size: Size{Height: *d.o.Bounds.Height, Width: *d.o.Bounds.Width}, } }
[ "func", "(", "d", "Display", ")", "Bounds", "(", ")", "Rectangle", "{", "return", "Rectangle", "{", "Position", ":", "Position", "{", "X", ":", "*", "d", ".", "o", ".", "Bounds", ".", "X", ",", "Y", ":", "*", "d", ".", "o", ".", "Bounds", ".", ...
// Bounds returns the display bounds
[ "Bounds", "returns", "the", "display", "bounds" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/display.go#L34-L39
164,319
asticode/go-astilectron
display.go
Size
func (d Display) Size() Size { return Size{Height: *d.o.Size.Height, Width: *d.o.Size.Width} }
go
func (d Display) Size() Size { return Size{Height: *d.o.Size.Height, Width: *d.o.Size.Width} }
[ "func", "(", "d", "Display", ")", "Size", "(", ")", "Size", "{", "return", "Size", "{", "Height", ":", "*", "d", ".", "o", ".", "Size", ".", "Height", ",", "Width", ":", "*", "d", ".", "o", ".", "Size", ".", "Width", "}", "\n", "}" ]
// Size returns the display size
[ "Size", "returns", "the", "display", "size" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/display.go#L62-L64
164,320
asticode/go-astilectron
display.go
WorkAreaSize
func (d Display) WorkAreaSize() Size { return Size{Height: *d.o.WorkAreaSize.Height, Width: *d.o.WorkAreaSize.Width} }
go
func (d Display) WorkAreaSize() Size { return Size{Height: *d.o.WorkAreaSize.Height, Width: *d.o.WorkAreaSize.Width} }
[ "func", "(", "d", "Display", ")", "WorkAreaSize", "(", ")", "Size", "{", "return", "Size", "{", "Height", ":", "*", "d", ".", "o", ".", "WorkAreaSize", ".", "Height", ",", "Width", ":", "*", "d", ".", "o", ".", "WorkAreaSize", ".", "Width", "}", ...
// WorkAreaSize returns the display work area size
[ "WorkAreaSize", "returns", "the", "display", "work", "area", "size" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/display.go#L75-L77
164,321
asticode/go-astilectron
window.go
newWindow
func newWindow(o Options, p Paths, url string, wo *WindowOptions, c *asticontext.Canceller, d *dispatcher, i *identifier, wrt *writer) (w *Window, err error) { // Init w = &Window{ callbackIdentifier: newIdentifier(), o: wo, object: newObject(nil, c, d, i, wrt, i.new()), } w.Session = newSession(w.ctx, c, d, i, wrt) // Check app details if wo.Icon == nil && p.AppIconDefaultSrc() != "" { wo.Icon = PtrStr(p.AppIconDefaultSrc()) } if wo.Title == nil && o.AppName != "" { wo.Title = PtrStr(o.AppName) } // Make sure the window's context is cancelled once the closed event is received w.On(EventNameWindowEventClosed, func(e Event) (deleteListener bool) { w.cancel() return true }) // Show w.On(EventNameWindowEventHide, func(e Event) (deleteListener bool) { w.m.Lock() defer w.m.Unlock() w.o.Show = PtrBool(false) return }) w.On(EventNameWindowEventShow, func(e Event) (deleteListener bool) { w.m.Lock() defer w.m.Unlock() w.o.Show = PtrBool(true) return }) // Parse url if w.url, err = astiurl.Parse(url); err != nil { err = errors.Wrapf(err, "parsing url %s failed", url) return } return }
go
func newWindow(o Options, p Paths, url string, wo *WindowOptions, c *asticontext.Canceller, d *dispatcher, i *identifier, wrt *writer) (w *Window, err error) { // Init w = &Window{ callbackIdentifier: newIdentifier(), o: wo, object: newObject(nil, c, d, i, wrt, i.new()), } w.Session = newSession(w.ctx, c, d, i, wrt) // Check app details if wo.Icon == nil && p.AppIconDefaultSrc() != "" { wo.Icon = PtrStr(p.AppIconDefaultSrc()) } if wo.Title == nil && o.AppName != "" { wo.Title = PtrStr(o.AppName) } // Make sure the window's context is cancelled once the closed event is received w.On(EventNameWindowEventClosed, func(e Event) (deleteListener bool) { w.cancel() return true }) // Show w.On(EventNameWindowEventHide, func(e Event) (deleteListener bool) { w.m.Lock() defer w.m.Unlock() w.o.Show = PtrBool(false) return }) w.On(EventNameWindowEventShow, func(e Event) (deleteListener bool) { w.m.Lock() defer w.m.Unlock() w.o.Show = PtrBool(true) return }) // Parse url if w.url, err = astiurl.Parse(url); err != nil { err = errors.Wrapf(err, "parsing url %s failed", url) return } return }
[ "func", "newWindow", "(", "o", "Options", ",", "p", "Paths", ",", "url", "string", ",", "wo", "*", "WindowOptions", ",", "c", "*", "asticontext", ".", "Canceller", ",", "d", "*", "dispatcher", ",", "i", "*", "identifier", ",", "wrt", "*", "writer", "...
// newWindow creates a new window
[ "newWindow", "creates", "a", "new", "window" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/window.go#L196-L239
164,322
asticode/go-astilectron
window.go
NewMenu
func (w *Window) NewMenu(i []*MenuItemOptions) *Menu { return newMenu(w.ctx, w.id, i, w.c, w.d, w.i, w.w) }
go
func (w *Window) NewMenu(i []*MenuItemOptions) *Menu { return newMenu(w.ctx, w.id, i, w.c, w.d, w.i, w.w) }
[ "func", "(", "w", "*", "Window", ")", "NewMenu", "(", "i", "[", "]", "*", "MenuItemOptions", ")", "*", "Menu", "{", "return", "newMenu", "(", "w", ".", "ctx", ",", "w", ".", "id", ",", "i", ",", "w", ".", "c", ",", "w", ".", "d", ",", "w", ...
// NewMenu creates a new window menu
[ "NewMenu", "creates", "a", "new", "window", "menu" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/window.go#L242-L244
164,323
asticode/go-astilectron
window.go
Blur
func (w *Window) Blur() (err error) { if err = w.isActionable(); err != nil { return } _, err = synchronousEvent(w.c, w, w.w, Event{Name: EventNameWindowCmdBlur, TargetID: w.id}, EventNameWindowEventBlur) return }
go
func (w *Window) Blur() (err error) { if err = w.isActionable(); err != nil { return } _, err = synchronousEvent(w.c, w, w.w, Event{Name: EventNameWindowCmdBlur, TargetID: w.id}, EventNameWindowEventBlur) return }
[ "func", "(", "w", "*", "Window", ")", "Blur", "(", ")", "(", "err", "error", ")", "{", "if", "err", "=", "w", ".", "isActionable", "(", ")", ";", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "_", ",", "err", "=", "synchronousEvent", "(",...
// Blur blurs the window
[ "Blur", "blurs", "the", "window" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/window.go#L247-L253
164,324
asticode/go-astilectron
window.go
Center
func (w *Window) Center() (err error) { if err = w.isActionable(); err != nil { return } _, err = synchronousEvent(w.c, w, w.w, Event{Name: EventNameWindowCmdCenter, TargetID: w.id}, EventNameWindowEventMove) return }
go
func (w *Window) Center() (err error) { if err = w.isActionable(); err != nil { return } _, err = synchronousEvent(w.c, w, w.w, Event{Name: EventNameWindowCmdCenter, TargetID: w.id}, EventNameWindowEventMove) return }
[ "func", "(", "w", "*", "Window", ")", "Center", "(", ")", "(", "err", "error", ")", "{", "if", "err", "=", "w", ".", "isActionable", "(", ")", ";", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "_", ",", "err", "=", "synchronousEvent", "(...
// Center centers the window
[ "Center", "centers", "the", "window" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/window.go#L256-L262
164,325
asticode/go-astilectron
window.go
Close
func (w *Window) Close() (err error) { if err = w.isActionable(); err != nil { return } _, err = synchronousEvent(w.c, w, w.w, Event{Name: EventNameWindowCmdClose, TargetID: w.id}, EventNameWindowEventClosed) return }
go
func (w *Window) Close() (err error) { if err = w.isActionable(); err != nil { return } _, err = synchronousEvent(w.c, w, w.w, Event{Name: EventNameWindowCmdClose, TargetID: w.id}, EventNameWindowEventClosed) return }
[ "func", "(", "w", "*", "Window", ")", "Close", "(", ")", "(", "err", "error", ")", "{", "if", "err", "=", "w", ".", "isActionable", "(", ")", ";", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "_", ",", "err", "=", "synchronousEvent", "("...
// Close closes the window
[ "Close", "closes", "the", "window" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/window.go#L265-L271
164,326
asticode/go-astilectron
window.go
CloseDevTools
func (w *Window) CloseDevTools() (err error) { if err = w.isActionable(); err != nil { return } return w.w.write(Event{Name: EventNameWindowCmdWebContentsCloseDevTools, TargetID: w.id}) }
go
func (w *Window) CloseDevTools() (err error) { if err = w.isActionable(); err != nil { return } return w.w.write(Event{Name: EventNameWindowCmdWebContentsCloseDevTools, TargetID: w.id}) }
[ "func", "(", "w", "*", "Window", ")", "CloseDevTools", "(", ")", "(", "err", "error", ")", "{", "if", "err", "=", "w", ".", "isActionable", "(", ")", ";", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "return", "w", ".", "w", ".", "write"...
// CloseDevTools closes the dev tools
[ "CloseDevTools", "closes", "the", "dev", "tools" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/window.go#L274-L279
164,327
asticode/go-astilectron
window.go
Create
func (w *Window) Create() (err error) { if err = w.isActionable(); err != nil { return } _, err = synchronousEvent(w.c, w, w.w, Event{Name: EventNameWindowCmdCreate, SessionID: w.Session.id, TargetID: w.id, URL: w.url.String(), WindowOptions: w.o}, EventNameWindowEventDidFinishLoad) return }
go
func (w *Window) Create() (err error) { if err = w.isActionable(); err != nil { return } _, err = synchronousEvent(w.c, w, w.w, Event{Name: EventNameWindowCmdCreate, SessionID: w.Session.id, TargetID: w.id, URL: w.url.String(), WindowOptions: w.o}, EventNameWindowEventDidFinishLoad) return }
[ "func", "(", "w", "*", "Window", ")", "Create", "(", ")", "(", "err", "error", ")", "{", "if", "err", "=", "w", ".", "isActionable", "(", ")", ";", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "_", ",", "err", "=", "synchronousEvent", "(...
// Create creates the window // We wait for EventNameWindowEventDidFinishLoad since we need the web content to be fully loaded before being able to // send messages to it
[ "Create", "creates", "the", "window", "We", "wait", "for", "EventNameWindowEventDidFinishLoad", "since", "we", "need", "the", "web", "content", "to", "be", "fully", "loaded", "before", "being", "able", "to", "send", "messages", "to", "it" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/window.go#L284-L290
164,328
asticode/go-astilectron
window.go
Destroy
func (w *Window) Destroy() (err error) { if err = w.isActionable(); err != nil { return } _, err = synchronousEvent(w.c, w, w.w, Event{Name: EventNameWindowCmdDestroy, TargetID: w.id}, EventNameWindowEventClosed) return }
go
func (w *Window) Destroy() (err error) { if err = w.isActionable(); err != nil { return } _, err = synchronousEvent(w.c, w, w.w, Event{Name: EventNameWindowCmdDestroy, TargetID: w.id}, EventNameWindowEventClosed) return }
[ "func", "(", "w", "*", "Window", ")", "Destroy", "(", ")", "(", "err", "error", ")", "{", "if", "err", "=", "w", ".", "isActionable", "(", ")", ";", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "_", ",", "err", "=", "synchronousEvent", "...
// Destroy destroys the window
[ "Destroy", "destroys", "the", "window" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/window.go#L293-L299
164,329
asticode/go-astilectron
window.go
Focus
func (w *Window) Focus() (err error) { if err = w.isActionable(); err != nil { return } _, err = synchronousEvent(w.c, w, w.w, Event{Name: EventNameWindowCmdFocus, TargetID: w.id}, EventNameWindowEventFocus) return }
go
func (w *Window) Focus() (err error) { if err = w.isActionable(); err != nil { return } _, err = synchronousEvent(w.c, w, w.w, Event{Name: EventNameWindowCmdFocus, TargetID: w.id}, EventNameWindowEventFocus) return }
[ "func", "(", "w", "*", "Window", ")", "Focus", "(", ")", "(", "err", "error", ")", "{", "if", "err", "=", "w", ".", "isActionable", "(", ")", ";", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "_", ",", "err", "=", "synchronousEvent", "("...
// Focus focuses on the window
[ "Focus", "focuses", "on", "the", "window" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/window.go#L302-L308
164,330
asticode/go-astilectron
window.go
Hide
func (w *Window) Hide() (err error) { if err = w.isActionable(); err != nil { return } _, err = synchronousEvent(w.c, w, w.w, Event{Name: EventNameWindowCmdHide, TargetID: w.id}, EventNameWindowEventHide) return }
go
func (w *Window) Hide() (err error) { if err = w.isActionable(); err != nil { return } _, err = synchronousEvent(w.c, w, w.w, Event{Name: EventNameWindowCmdHide, TargetID: w.id}, EventNameWindowEventHide) return }
[ "func", "(", "w", "*", "Window", ")", "Hide", "(", ")", "(", "err", "error", ")", "{", "if", "err", "=", "w", ".", "isActionable", "(", ")", ";", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "_", ",", "err", "=", "synchronousEvent", "(",...
// Hide hides the window
[ "Hide", "hides", "the", "window" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/window.go#L311-L317
164,331
asticode/go-astilectron
window.go
IsShown
func (w *Window) IsShown() bool { if err := w.isActionable(); err != nil { return false } w.m.Lock() defer w.m.Unlock() return w.o.Show != nil && *w.o.Show }
go
func (w *Window) IsShown() bool { if err := w.isActionable(); err != nil { return false } w.m.Lock() defer w.m.Unlock() return w.o.Show != nil && *w.o.Show }
[ "func", "(", "w", "*", "Window", ")", "IsShown", "(", ")", "bool", "{", "if", "err", ":=", "w", ".", "isActionable", "(", ")", ";", "err", "!=", "nil", "{", "return", "false", "\n", "}", "\n", "w", ".", "m", ".", "Lock", "(", ")", "\n", "defe...
// IsShown returns whether the window is shown
[ "IsShown", "returns", "whether", "the", "window", "is", "shown" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/window.go#L320-L327
164,332
asticode/go-astilectron
window.go
Log
func (w *Window) Log(message string) (err error) { if err = w.isActionable(); err != nil { return } return w.w.write(Event{Message: newEventMessage(message), Name: EventNameWindowCmdLog, TargetID: w.id}) }
go
func (w *Window) Log(message string) (err error) { if err = w.isActionable(); err != nil { return } return w.w.write(Event{Message: newEventMessage(message), Name: EventNameWindowCmdLog, TargetID: w.id}) }
[ "func", "(", "w", "*", "Window", ")", "Log", "(", "message", "string", ")", "(", "err", "error", ")", "{", "if", "err", "=", "w", ".", "isActionable", "(", ")", ";", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "return", "w", ".", "w", ...
// Log logs a message in the JS console of the window
[ "Log", "logs", "a", "message", "in", "the", "JS", "console", "of", "the", "window" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/window.go#L330-L335
164,333
asticode/go-astilectron
window.go
Maximize
func (w *Window) Maximize() (err error) { if err = w.isActionable(); err != nil { return } _, err = synchronousEvent(w.c, w, w.w, Event{Name: EventNameWindowCmdMaximize, TargetID: w.id}, EventNameWindowEventMaximize) return }
go
func (w *Window) Maximize() (err error) { if err = w.isActionable(); err != nil { return } _, err = synchronousEvent(w.c, w, w.w, Event{Name: EventNameWindowCmdMaximize, TargetID: w.id}, EventNameWindowEventMaximize) return }
[ "func", "(", "w", "*", "Window", ")", "Maximize", "(", ")", "(", "err", "error", ")", "{", "if", "err", "=", "w", ".", "isActionable", "(", ")", ";", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "_", ",", "err", "=", "synchronousEvent", ...
// Maximize maximizes the window
[ "Maximize", "maximizes", "the", "window" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/window.go#L338-L344
164,334
asticode/go-astilectron
window.go
Minimize
func (w *Window) Minimize() (err error) { if err = w.isActionable(); err != nil { return } _, err = synchronousEvent(w.c, w, w.w, Event{Name: EventNameWindowCmdMinimize, TargetID: w.id}, EventNameWindowEventMinimize) return }
go
func (w *Window) Minimize() (err error) { if err = w.isActionable(); err != nil { return } _, err = synchronousEvent(w.c, w, w.w, Event{Name: EventNameWindowCmdMinimize, TargetID: w.id}, EventNameWindowEventMinimize) return }
[ "func", "(", "w", "*", "Window", ")", "Minimize", "(", ")", "(", "err", "error", ")", "{", "if", "err", "=", "w", ".", "isActionable", "(", ")", ";", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "_", ",", "err", "=", "synchronousEvent", ...
// Minimize minimizes the window
[ "Minimize", "minimizes", "the", "window" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/window.go#L347-L353
164,335
asticode/go-astilectron
window.go
Move
func (w *Window) Move(x, y int) (err error) { if err = w.isActionable(); err != nil { return } w.m.Lock() w.o.X = PtrInt(x) w.o.Y = PtrInt(y) w.m.Unlock() _, err = synchronousEvent(w.c, w, w.w, Event{Name: EventNameWindowCmdMove, TargetID: w.id, WindowOptions: &WindowOptions{X: PtrInt(x), Y: PtrInt(y)}}, EventNameWindowEventMove) return }
go
func (w *Window) Move(x, y int) (err error) { if err = w.isActionable(); err != nil { return } w.m.Lock() w.o.X = PtrInt(x) w.o.Y = PtrInt(y) w.m.Unlock() _, err = synchronousEvent(w.c, w, w.w, Event{Name: EventNameWindowCmdMove, TargetID: w.id, WindowOptions: &WindowOptions{X: PtrInt(x), Y: PtrInt(y)}}, EventNameWindowEventMove) return }
[ "func", "(", "w", "*", "Window", ")", "Move", "(", "x", ",", "y", "int", ")", "(", "err", "error", ")", "{", "if", "err", "=", "w", ".", "isActionable", "(", ")", ";", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "w", ".", "m", ".", ...
// Move moves the window
[ "Move", "moves", "the", "window" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/window.go#L356-L366
164,336
asticode/go-astilectron
window.go
MoveInDisplay
func (w *Window) MoveInDisplay(d *Display, x, y int) error { return w.Move(d.Bounds().X+x, d.Bounds().Y+y) }
go
func (w *Window) MoveInDisplay(d *Display, x, y int) error { return w.Move(d.Bounds().X+x, d.Bounds().Y+y) }
[ "func", "(", "w", "*", "Window", ")", "MoveInDisplay", "(", "d", "*", "Display", ",", "x", ",", "y", "int", ")", "error", "{", "return", "w", ".", "Move", "(", "d", ".", "Bounds", "(", ")", ".", "X", "+", "x", ",", "d", ".", "Bounds", "(", ...
// MoveInDisplay moves the window in the proper display
[ "MoveInDisplay", "moves", "the", "window", "in", "the", "proper", "display" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/window.go#L369-L371
164,337
asticode/go-astilectron
window.go
OnMessage
func (w *Window) OnMessage(l ListenerMessage) { w.onMessageOnce.Do(func() { w.On(eventNameWindowEventMessage, func(i Event) (deleteListener bool) { v := l(i.Message) if len(i.CallbackID) > 0 { o := Event{CallbackID: i.CallbackID, Name: eventNameWindowCmdMessageCallback, TargetID: w.id} if v != nil { o.Message = newEventMessage(v) } if err := w.w.write(o); err != nil { astilog.Error(errors.Wrap(err, "writing callback message failed")) } } return }) }) }
go
func (w *Window) OnMessage(l ListenerMessage) { w.onMessageOnce.Do(func() { w.On(eventNameWindowEventMessage, func(i Event) (deleteListener bool) { v := l(i.Message) if len(i.CallbackID) > 0 { o := Event{CallbackID: i.CallbackID, Name: eventNameWindowCmdMessageCallback, TargetID: w.id} if v != nil { o.Message = newEventMessage(v) } if err := w.w.write(o); err != nil { astilog.Error(errors.Wrap(err, "writing callback message failed")) } } return }) }) }
[ "func", "(", "w", "*", "Window", ")", "OnMessage", "(", "l", "ListenerMessage", ")", "{", "w", ".", "onMessageOnce", ".", "Do", "(", "func", "(", ")", "{", "w", ".", "On", "(", "eventNameWindowEventMessage", ",", "func", "(", "i", "Event", ")", "(", ...
// OnMessage adds a specific listener executed when receiving a message from the JS // This method can be called only once
[ "OnMessage", "adds", "a", "specific", "listener", "executed", "when", "receiving", "a", "message", "from", "the", "JS", "This", "method", "can", "be", "called", "only", "once" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/window.go#L401-L417
164,338
asticode/go-astilectron
window.go
OpenDevTools
func (w *Window) OpenDevTools() (err error) { if err = w.isActionable(); err != nil { return } return w.w.write(Event{Name: EventNameWindowCmdWebContentsOpenDevTools, TargetID: w.id}) }
go
func (w *Window) OpenDevTools() (err error) { if err = w.isActionable(); err != nil { return } return w.w.write(Event{Name: EventNameWindowCmdWebContentsOpenDevTools, TargetID: w.id}) }
[ "func", "(", "w", "*", "Window", ")", "OpenDevTools", "(", ")", "(", "err", "error", ")", "{", "if", "err", "=", "w", ".", "isActionable", "(", ")", ";", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "return", "w", ".", "w", ".", "write",...
// OpenDevTools opens the dev tools
[ "OpenDevTools", "opens", "the", "dev", "tools" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/window.go#L420-L425
164,339
asticode/go-astilectron
window.go
Resize
func (w *Window) Resize(width, height int) (err error) { if err = w.isActionable(); err != nil { return } w.m.Lock() w.o.Height = PtrInt(height) w.o.Width = PtrInt(width) w.m.Unlock() _, err = synchronousEvent(w.c, w, w.w, Event{Name: EventNameWindowCmdResize, TargetID: w.id, WindowOptions: &WindowOptions{Height: PtrInt(height), Width: PtrInt(width)}}, EventNameWindowEventResize) return }
go
func (w *Window) Resize(width, height int) (err error) { if err = w.isActionable(); err != nil { return } w.m.Lock() w.o.Height = PtrInt(height) w.o.Width = PtrInt(width) w.m.Unlock() _, err = synchronousEvent(w.c, w, w.w, Event{Name: EventNameWindowCmdResize, TargetID: w.id, WindowOptions: &WindowOptions{Height: PtrInt(height), Width: PtrInt(width)}}, EventNameWindowEventResize) return }
[ "func", "(", "w", "*", "Window", ")", "Resize", "(", "width", ",", "height", "int", ")", "(", "err", "error", ")", "{", "if", "err", "=", "w", ".", "isActionable", "(", ")", ";", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "w", ".", "...
// Resize resizes the window
[ "Resize", "resizes", "the", "window" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/window.go#L428-L438
164,340
asticode/go-astilectron
window.go
SetBounds
func (w *Window) SetBounds(r RectangleOptions) (err error) { if err = w.isActionable(); err != nil { return } w.m.Lock() w.o.Height = r.Height w.o.Width = r.Width w.o.X = r.X w.o.Y = r.Y w.m.Unlock() _, err = synchronousEvent(w.c, w, w.w, Event{Name: EventNameWindowCmdSetBounds, TargetID: w.id, Bounds: &r}, EventNameWindowEventResize) return }
go
func (w *Window) SetBounds(r RectangleOptions) (err error) { if err = w.isActionable(); err != nil { return } w.m.Lock() w.o.Height = r.Height w.o.Width = r.Width w.o.X = r.X w.o.Y = r.Y w.m.Unlock() _, err = synchronousEvent(w.c, w, w.w, Event{Name: EventNameWindowCmdSetBounds, TargetID: w.id, Bounds: &r}, EventNameWindowEventResize) return }
[ "func", "(", "w", "*", "Window", ")", "SetBounds", "(", "r", "RectangleOptions", ")", "(", "err", "error", ")", "{", "if", "err", "=", "w", ".", "isActionable", "(", ")", ";", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "w", ".", "m", "...
// SetBounds set bounds of the window
[ "SetBounds", "set", "bounds", "of", "the", "window" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/window.go#L441-L453
164,341
asticode/go-astilectron
window.go
Restore
func (w *Window) Restore() (err error) { if err = w.isActionable(); err != nil { return } _, err = synchronousEvent(w.c, w, w.w, Event{Name: EventNameWindowCmdRestore, TargetID: w.id}, EventNameWindowEventRestore) return }
go
func (w *Window) Restore() (err error) { if err = w.isActionable(); err != nil { return } _, err = synchronousEvent(w.c, w, w.w, Event{Name: EventNameWindowCmdRestore, TargetID: w.id}, EventNameWindowEventRestore) return }
[ "func", "(", "w", "*", "Window", ")", "Restore", "(", ")", "(", "err", "error", ")", "{", "if", "err", "=", "w", ".", "isActionable", "(", ")", ";", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "_", ",", "err", "=", "synchronousEvent", "...
// Restore restores the window
[ "Restore", "restores", "the", "window" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/window.go#L456-L462
164,342
asticode/go-astilectron
window.go
SendMessage
func (w *Window) SendMessage(message interface{}, callbacks ...CallbackMessage) (err error) { if err = w.isActionable(); err != nil { return } var e = Event{Message: newEventMessage(message), Name: eventNameWindowCmdMessage, TargetID: w.id} if len(callbacks) > 0 { e.CallbackID = w.callbackIdentifier.new() w.On(eventNameWindowEventMessageCallback, func(i Event) (deleteListener bool) { if i.CallbackID == e.CallbackID { for _, c := range callbacks { c(i.Message) } deleteListener = true } return }) } return w.w.write(e) }
go
func (w *Window) SendMessage(message interface{}, callbacks ...CallbackMessage) (err error) { if err = w.isActionable(); err != nil { return } var e = Event{Message: newEventMessage(message), Name: eventNameWindowCmdMessage, TargetID: w.id} if len(callbacks) > 0 { e.CallbackID = w.callbackIdentifier.new() w.On(eventNameWindowEventMessageCallback, func(i Event) (deleteListener bool) { if i.CallbackID == e.CallbackID { for _, c := range callbacks { c(i.Message) } deleteListener = true } return }) } return w.w.write(e) }
[ "func", "(", "w", "*", "Window", ")", "SendMessage", "(", "message", "interface", "{", "}", ",", "callbacks", "...", "CallbackMessage", ")", "(", "err", "error", ")", "{", "if", "err", "=", "w", ".", "isActionable", "(", ")", ";", "err", "!=", "nil",...
// SendMessage sends a message to the JS window and execute optional callbacks upon receiving a response from the JS // Use astilectron.onMessage method to capture those messages in JS
[ "SendMessage", "sends", "a", "message", "to", "the", "JS", "window", "and", "execute", "optional", "callbacks", "upon", "receiving", "a", "response", "from", "the", "JS", "Use", "astilectron", ".", "onMessage", "method", "to", "capture", "those", "messages", "...
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/window.go#L469-L487
164,343
asticode/go-astilectron
window.go
Show
func (w *Window) Show() (err error) { if err = w.isActionable(); err != nil { return } _, err = synchronousEvent(w.c, w, w.w, Event{Name: EventNameWindowCmdShow, TargetID: w.id}, EventNameWindowEventShow) return }
go
func (w *Window) Show() (err error) { if err = w.isActionable(); err != nil { return } _, err = synchronousEvent(w.c, w, w.w, Event{Name: EventNameWindowCmdShow, TargetID: w.id}, EventNameWindowEventShow) return }
[ "func", "(", "w", "*", "Window", ")", "Show", "(", ")", "(", "err", "error", ")", "{", "if", "err", "=", "w", ".", "isActionable", "(", ")", ";", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "_", ",", "err", "=", "synchronousEvent", "(",...
// Show shows the window
[ "Show", "shows", "the", "window" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/window.go#L490-L496
164,344
asticode/go-astilectron
window.go
Unmaximize
func (w *Window) Unmaximize() (err error) { if err = w.isActionable(); err != nil { return } _, err = synchronousEvent(w.c, w, w.w, Event{Name: EventNameWindowCmdUnmaximize, TargetID: w.id}, EventNameWindowEventUnmaximize) return }
go
func (w *Window) Unmaximize() (err error) { if err = w.isActionable(); err != nil { return } _, err = synchronousEvent(w.c, w, w.w, Event{Name: EventNameWindowCmdUnmaximize, TargetID: w.id}, EventNameWindowEventUnmaximize) return }
[ "func", "(", "w", "*", "Window", ")", "Unmaximize", "(", ")", "(", "err", "error", ")", "{", "if", "err", "=", "w", ".", "isActionable", "(", ")", ";", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "_", ",", "err", "=", "synchronousEvent", ...
// Unmaximize unmaximize the window
[ "Unmaximize", "unmaximize", "the", "window" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/window.go#L499-L505
164,345
adnanh/webhook
hook/hook.go
CheckPayloadSignature
func CheckPayloadSignature(payload []byte, secret string, signature string) (string, error) { signature = strings.TrimPrefix(signature, "sha1=") mac := hmac.New(sha1.New, []byte(secret)) _, err := mac.Write(payload) if err != nil { return "", err } expectedMAC := hex.EncodeToString(mac.Sum(nil)) if !hmac.Equal([]byte(signature), []byte(expectedMAC)) { return expectedMAC, &SignatureError{signature} } return expectedMAC, err }
go
func CheckPayloadSignature(payload []byte, secret string, signature string) (string, error) { signature = strings.TrimPrefix(signature, "sha1=") mac := hmac.New(sha1.New, []byte(secret)) _, err := mac.Write(payload) if err != nil { return "", err } expectedMAC := hex.EncodeToString(mac.Sum(nil)) if !hmac.Equal([]byte(signature), []byte(expectedMAC)) { return expectedMAC, &SignatureError{signature} } return expectedMAC, err }
[ "func", "CheckPayloadSignature", "(", "payload", "[", "]", "byte", ",", "secret", "string", ",", "signature", "string", ")", "(", "string", ",", "error", ")", "{", "signature", "=", "strings", ".", "TrimPrefix", "(", "signature", ",", "\"", "\"", ")", "\...
// CheckPayloadSignature calculates and verifies SHA1 signature of the given payload
[ "CheckPayloadSignature", "calculates", "and", "verifies", "SHA1", "signature", "of", "the", "given", "payload" ]
0aa7395e2191278c090ecadc94472f6205cd9a01
https://github.com/adnanh/webhook/blob/0aa7395e2191278c090ecadc94472f6205cd9a01/hook/hook.go#L96-L110
164,346
adnanh/webhook
hook/hook.go
Get
func (ha *Argument) Get(headers, query, payload *map[string]interface{}) (string, bool) { var source *map[string]interface{} key := ha.Name switch ha.Source { case SourceHeader: source = headers key = textproto.CanonicalMIMEHeaderKey(ha.Name) case SourceQuery, SourceQueryAlias: source = query case SourcePayload: source = payload case SourceString: return ha.Name, true case SourceEntirePayload: r, err := json.Marshal(payload) if err != nil { return "", false } return string(r), true case SourceEntireHeaders: r, err := json.Marshal(headers) if err != nil { return "", false } return string(r), true case SourceEntireQuery: r, err := json.Marshal(query) if err != nil { return "", false } return string(r), true } if source != nil { return ExtractParameterAsString(key, *source) } return "", false }
go
func (ha *Argument) Get(headers, query, payload *map[string]interface{}) (string, bool) { var source *map[string]interface{} key := ha.Name switch ha.Source { case SourceHeader: source = headers key = textproto.CanonicalMIMEHeaderKey(ha.Name) case SourceQuery, SourceQueryAlias: source = query case SourcePayload: source = payload case SourceString: return ha.Name, true case SourceEntirePayload: r, err := json.Marshal(payload) if err != nil { return "", false } return string(r), true case SourceEntireHeaders: r, err := json.Marshal(headers) if err != nil { return "", false } return string(r), true case SourceEntireQuery: r, err := json.Marshal(query) if err != nil { return "", false } return string(r), true } if source != nil { return ExtractParameterAsString(key, *source) } return "", false }
[ "func", "(", "ha", "*", "Argument", ")", "Get", "(", "headers", ",", "query", ",", "payload", "*", "map", "[", "string", "]", "interface", "{", "}", ")", "(", "string", ",", "bool", ")", "{", "var", "source", "*", "map", "[", "string", "]", "inte...
// Get Argument method returns the value for the Argument's key name // based on the Argument's source
[ "Get", "Argument", "method", "returns", "the", "value", "for", "the", "Argument", "s", "key", "name", "based", "on", "the", "Argument", "s", "source" ]
0aa7395e2191278c090ecadc94472f6205cd9a01
https://github.com/adnanh/webhook/blob/0aa7395e2191278c090ecadc94472f6205cd9a01/hook/hook.go#L314-L359
164,347
adnanh/webhook
hook/hook.go
Set
func (h *ResponseHeaders) Set(value string) error { splitResult := strings.SplitN(value, "=", 2) if len(splitResult) != 2 { return errors.New("header flag must be in name=value format") } *h = append(*h, Header{Name: splitResult[0], Value: splitResult[1]}) return nil }
go
func (h *ResponseHeaders) Set(value string) error { splitResult := strings.SplitN(value, "=", 2) if len(splitResult) != 2 { return errors.New("header flag must be in name=value format") } *h = append(*h, Header{Name: splitResult[0], Value: splitResult[1]}) return nil }
[ "func", "(", "h", "*", "ResponseHeaders", ")", "Set", "(", "value", "string", ")", "error", "{", "splitResult", ":=", "strings", ".", "SplitN", "(", "value", ",", "\"", "\"", ",", "2", ")", "\n\n", "if", "len", "(", "splitResult", ")", "!=", "2", "...
// Set method appends new Header object from header=value notation
[ "Set", "method", "appends", "new", "Header", "object", "from", "header", "=", "value", "notation" ]
0aa7395e2191278c090ecadc94472f6205cd9a01
https://github.com/adnanh/webhook/blob/0aa7395e2191278c090ecadc94472f6205cd9a01/hook/hook.go#L386-L395
164,348
adnanh/webhook
hook/hook.go
Set
func (h *HooksFiles) Set(value string) error { *h = append(*h, value) return nil }
go
func (h *HooksFiles) Set(value string) error { *h = append(*h, value) return nil }
[ "func", "(", "h", "*", "HooksFiles", ")", "Set", "(", "value", "string", ")", "error", "{", "*", "h", "=", "append", "(", "*", "h", ",", "value", ")", "\n", "return", "nil", "\n", "}" ]
// Set method appends new string
[ "Set", "method", "appends", "new", "string" ]
0aa7395e2191278c090ecadc94472f6205cd9a01
https://github.com/adnanh/webhook/blob/0aa7395e2191278c090ecadc94472f6205cd9a01/hook/hook.go#L409-L412
164,349
adnanh/webhook
hook/hook.go
ParseJSONParameters
func (h *Hook) ParseJSONParameters(headers, query, payload *map[string]interface{}) []error { var errors = make([]error, 0) for i := range h.JSONStringParameters { if arg, ok := h.JSONStringParameters[i].Get(headers, query, payload); ok { var newArg map[string]interface{} decoder := json.NewDecoder(strings.NewReader(string(arg))) decoder.UseNumber() err := decoder.Decode(&newArg) if err != nil { errors = append(errors, &ParseError{err}) continue } var source *map[string]interface{} switch h.JSONStringParameters[i].Source { case SourceHeader: source = headers case SourcePayload: source = payload case SourceQuery, SourceQueryAlias: source = query } if source != nil { key := h.JSONStringParameters[i].Name if h.JSONStringParameters[i].Source == SourceHeader { key = textproto.CanonicalMIMEHeaderKey(h.JSONStringParameters[i].Name) } ReplaceParameter(key, source, newArg) } else { errors = append(errors, &SourceError{h.JSONStringParameters[i]}) } } else { errors = append(errors, &ArgumentError{h.JSONStringParameters[i]}) } } if len(errors) > 0 { return errors } return nil }
go
func (h *Hook) ParseJSONParameters(headers, query, payload *map[string]interface{}) []error { var errors = make([]error, 0) for i := range h.JSONStringParameters { if arg, ok := h.JSONStringParameters[i].Get(headers, query, payload); ok { var newArg map[string]interface{} decoder := json.NewDecoder(strings.NewReader(string(arg))) decoder.UseNumber() err := decoder.Decode(&newArg) if err != nil { errors = append(errors, &ParseError{err}) continue } var source *map[string]interface{} switch h.JSONStringParameters[i].Source { case SourceHeader: source = headers case SourcePayload: source = payload case SourceQuery, SourceQueryAlias: source = query } if source != nil { key := h.JSONStringParameters[i].Name if h.JSONStringParameters[i].Source == SourceHeader { key = textproto.CanonicalMIMEHeaderKey(h.JSONStringParameters[i].Name) } ReplaceParameter(key, source, newArg) } else { errors = append(errors, &SourceError{h.JSONStringParameters[i]}) } } else { errors = append(errors, &ArgumentError{h.JSONStringParameters[i]}) } } if len(errors) > 0 { return errors } return nil }
[ "func", "(", "h", "*", "Hook", ")", "ParseJSONParameters", "(", "headers", ",", "query", ",", "payload", "*", "map", "[", "string", "]", "interface", "{", "}", ")", "[", "]", "error", "{", "var", "errors", "=", "make", "(", "[", "]", "error", ",", ...
// ParseJSONParameters decodes specified arguments to JSON objects and replaces the // string with the newly created object
[ "ParseJSONParameters", "decodes", "specified", "arguments", "to", "JSON", "objects", "and", "replaces", "the", "string", "with", "the", "newly", "created", "object" ]
0aa7395e2191278c090ecadc94472f6205cd9a01
https://github.com/adnanh/webhook/blob/0aa7395e2191278c090ecadc94472f6205cd9a01/hook/hook.go#L434-L483
164,350
adnanh/webhook
hook/hook.go
Append
func (h *Hooks) Append(other *Hooks) error { for _, hook := range *other { if h.Match(hook.ID) != nil { return fmt.Errorf("hook with ID %s is already defined", hook.ID) } *h = append(*h, hook) } return nil }
go
func (h *Hooks) Append(other *Hooks) error { for _, hook := range *other { if h.Match(hook.ID) != nil { return fmt.Errorf("hook with ID %s is already defined", hook.ID) } *h = append(*h, hook) } return nil }
[ "func", "(", "h", "*", "Hooks", ")", "Append", "(", "other", "*", "Hooks", ")", "error", "{", "for", "_", ",", "hook", ":=", "range", "*", "other", "{", "if", "h", ".", "Match", "(", "hook", ".", "ID", ")", "!=", "nil", "{", "return", "fmt", ...
// Append appends hooks unless the new hooks contain a hook with an ID that already exists
[ "Append", "appends", "hooks", "unless", "the", "new", "hooks", "contain", "a", "hook", "with", "an", "ID", "that", "already", "exists" ]
0aa7395e2191278c090ecadc94472f6205cd9a01
https://github.com/adnanh/webhook/blob/0aa7395e2191278c090ecadc94472f6205cd9a01/hook/hook.go#L624-L634
164,351
adnanh/webhook
hook/hook.go
Match
func (h *Hooks) Match(id string) *Hook { for i := range *h { if (*h)[i].ID == id { return &(*h)[i] } } return nil }
go
func (h *Hooks) Match(id string) *Hook { for i := range *h { if (*h)[i].ID == id { return &(*h)[i] } } return nil }
[ "func", "(", "h", "*", "Hooks", ")", "Match", "(", "id", "string", ")", "*", "Hook", "{", "for", "i", ":=", "range", "*", "h", "{", "if", "(", "*", "h", ")", "[", "i", "]", ".", "ID", "==", "id", "{", "return", "&", "(", "*", "h", ")", ...
// Match iterates through Hooks and returns first one that matches the given ID, // if no hook matches the given ID, nil is returned
[ "Match", "iterates", "through", "Hooks", "and", "returns", "first", "one", "that", "matches", "the", "given", "ID", "if", "no", "hook", "matches", "the", "given", "ID", "nil", "is", "returned" ]
0aa7395e2191278c090ecadc94472f6205cd9a01
https://github.com/adnanh/webhook/blob/0aa7395e2191278c090ecadc94472f6205cd9a01/hook/hook.go#L638-L646
164,352
adnanh/webhook
hook/hook.go
Evaluate
func (r Rules) Evaluate(headers, query, payload *map[string]interface{}, body *[]byte, remoteAddr string) (bool, error) { switch { case r.And != nil: return r.And.Evaluate(headers, query, payload, body, remoteAddr) case r.Or != nil: return r.Or.Evaluate(headers, query, payload, body, remoteAddr) case r.Not != nil: return r.Not.Evaluate(headers, query, payload, body, remoteAddr) case r.Match != nil: return r.Match.Evaluate(headers, query, payload, body, remoteAddr) } return false, nil }
go
func (r Rules) Evaluate(headers, query, payload *map[string]interface{}, body *[]byte, remoteAddr string) (bool, error) { switch { case r.And != nil: return r.And.Evaluate(headers, query, payload, body, remoteAddr) case r.Or != nil: return r.Or.Evaluate(headers, query, payload, body, remoteAddr) case r.Not != nil: return r.Not.Evaluate(headers, query, payload, body, remoteAddr) case r.Match != nil: return r.Match.Evaluate(headers, query, payload, body, remoteAddr) } return false, nil }
[ "func", "(", "r", "Rules", ")", "Evaluate", "(", "headers", ",", "query", ",", "payload", "*", "map", "[", "string", "]", "interface", "{", "}", ",", "body", "*", "[", "]", "byte", ",", "remoteAddr", "string", ")", "(", "bool", ",", "error", ")", ...
// Evaluate finds the first rule property that is not nil and returns the value // it evaluates to
[ "Evaluate", "finds", "the", "first", "rule", "property", "that", "is", "not", "nil", "and", "returns", "the", "value", "it", "evaluates", "to" ]
0aa7395e2191278c090ecadc94472f6205cd9a01
https://github.com/adnanh/webhook/blob/0aa7395e2191278c090ecadc94472f6205cd9a01/hook/hook.go#L658-L671
164,353
adnanh/webhook
hook/hook.go
Evaluate
func (r AndRule) Evaluate(headers, query, payload *map[string]interface{}, body *[]byte, remoteAddr string) (bool, error) { res := true for _, v := range r { rv, err := v.Evaluate(headers, query, payload, body, remoteAddr) if err != nil { return false, err } res = res && rv if !res { return res, nil } } return res, nil }
go
func (r AndRule) Evaluate(headers, query, payload *map[string]interface{}, body *[]byte, remoteAddr string) (bool, error) { res := true for _, v := range r { rv, err := v.Evaluate(headers, query, payload, body, remoteAddr) if err != nil { return false, err } res = res && rv if !res { return res, nil } } return res, nil }
[ "func", "(", "r", "AndRule", ")", "Evaluate", "(", "headers", ",", "query", ",", "payload", "*", "map", "[", "string", "]", "interface", "{", "}", ",", "body", "*", "[", "]", "byte", ",", "remoteAddr", "string", ")", "(", "bool", ",", "error", ")",...
// Evaluate AndRule will return true if and only if all of ChildRules evaluate to true
[ "Evaluate", "AndRule", "will", "return", "true", "if", "and", "only", "if", "all", "of", "ChildRules", "evaluate", "to", "true" ]
0aa7395e2191278c090ecadc94472f6205cd9a01
https://github.com/adnanh/webhook/blob/0aa7395e2191278c090ecadc94472f6205cd9a01/hook/hook.go#L677-L693
164,354
adnanh/webhook
hook/hook.go
Evaluate
func (r NotRule) Evaluate(headers, query, payload *map[string]interface{}, body *[]byte, remoteAddr string) (bool, error) { rv, err := Rules(r).Evaluate(headers, query, payload, body, remoteAddr) return !rv, err }
go
func (r NotRule) Evaluate(headers, query, payload *map[string]interface{}, body *[]byte, remoteAddr string) (bool, error) { rv, err := Rules(r).Evaluate(headers, query, payload, body, remoteAddr) return !rv, err }
[ "func", "(", "r", "NotRule", ")", "Evaluate", "(", "headers", ",", "query", ",", "payload", "*", "map", "[", "string", "]", "interface", "{", "}", ",", "body", "*", "[", "]", "byte", ",", "remoteAddr", "string", ")", "(", "bool", ",", "error", ")",...
// Evaluate NotRule will return true if and only if ChildRule evaluates to false
[ "Evaluate", "NotRule", "will", "return", "true", "if", "and", "only", "if", "ChildRule", "evaluates", "to", "false" ]
0aa7395e2191278c090ecadc94472f6205cd9a01
https://github.com/adnanh/webhook/blob/0aa7395e2191278c090ecadc94472f6205cd9a01/hook/hook.go#L721-L724
164,355
adnanh/webhook
hook/hook.go
Evaluate
func (r MatchRule) Evaluate(headers, query, payload *map[string]interface{}, body *[]byte, remoteAddr string) (bool, error) { if r.Type == IPWhitelist { return CheckIPWhitelist(remoteAddr, r.IPRange) } if r.Type == ScalrSignature { return CheckScalrSignature(*headers, *body, r.Secret, true) } if arg, ok := r.Parameter.Get(headers, query, payload); ok { switch r.Type { case MatchValue: return arg == r.Value, nil case MatchRegex: return regexp.MatchString(r.Regex, arg) case MatchHashSHA1: _, err := CheckPayloadSignature(*body, r.Secret, arg) return err == nil, err case MatchHashSHA256: _, err := CheckPayloadSignature256(*body, r.Secret, arg) return err == nil, err } } return false, nil }
go
func (r MatchRule) Evaluate(headers, query, payload *map[string]interface{}, body *[]byte, remoteAddr string) (bool, error) { if r.Type == IPWhitelist { return CheckIPWhitelist(remoteAddr, r.IPRange) } if r.Type == ScalrSignature { return CheckScalrSignature(*headers, *body, r.Secret, true) } if arg, ok := r.Parameter.Get(headers, query, payload); ok { switch r.Type { case MatchValue: return arg == r.Value, nil case MatchRegex: return regexp.MatchString(r.Regex, arg) case MatchHashSHA1: _, err := CheckPayloadSignature(*body, r.Secret, arg) return err == nil, err case MatchHashSHA256: _, err := CheckPayloadSignature256(*body, r.Secret, arg) return err == nil, err } } return false, nil }
[ "func", "(", "r", "MatchRule", ")", "Evaluate", "(", "headers", ",", "query", ",", "payload", "*", "map", "[", "string", "]", "interface", "{", "}", ",", "body", "*", "[", "]", "byte", ",", "remoteAddr", "string", ")", "(", "bool", ",", "error", ")...
// Evaluate MatchRule will return based on the type
[ "Evaluate", "MatchRule", "will", "return", "based", "on", "the", "type" ]
0aa7395e2191278c090ecadc94472f6205cd9a01
https://github.com/adnanh/webhook/blob/0aa7395e2191278c090ecadc94472f6205cd9a01/hook/hook.go#L747-L770
164,356
google/netstack
tcpip/header/ipv6.go
SourceAddress
func (b IPv6) SourceAddress() tcpip.Address { return tcpip.Address(b[v6SrcAddr : v6SrcAddr+IPv6AddressSize]) }
go
func (b IPv6) SourceAddress() tcpip.Address { return tcpip.Address(b[v6SrcAddr : v6SrcAddr+IPv6AddressSize]) }
[ "func", "(", "b", "IPv6", ")", "SourceAddress", "(", ")", "tcpip", ".", "Address", "{", "return", "tcpip", ".", "Address", "(", "b", "[", "v6SrcAddr", ":", "v6SrcAddr", "+", "IPv6AddressSize", "]", ")", "\n", "}" ]
// SourceAddress returns the "source address" field of the ipv6 header.
[ "SourceAddress", "returns", "the", "source", "address", "field", "of", "the", "ipv6", "header", "." ]
70ebca9c30730cf3887cdef3b85bb96ed7a97593
https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/header/ipv6.go#L112-L114
164,357
google/netstack
tcpip/header/ipv6.go
DestinationAddress
func (b IPv6) DestinationAddress() tcpip.Address { return tcpip.Address(b[v6DstAddr : v6DstAddr+IPv6AddressSize]) }
go
func (b IPv6) DestinationAddress() tcpip.Address { return tcpip.Address(b[v6DstAddr : v6DstAddr+IPv6AddressSize]) }
[ "func", "(", "b", "IPv6", ")", "DestinationAddress", "(", ")", "tcpip", ".", "Address", "{", "return", "tcpip", ".", "Address", "(", "b", "[", "v6DstAddr", ":", "v6DstAddr", "+", "IPv6AddressSize", "]", ")", "\n", "}" ]
// DestinationAddress returns the "destination address" field of the ipv6 // header.
[ "DestinationAddress", "returns", "the", "destination", "address", "field", "of", "the", "ipv6", "header", "." ]
70ebca9c30730cf3887cdef3b85bb96ed7a97593
https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/header/ipv6.go#L118-L120
164,358
google/netstack
tcpip/header/ipv6.go
TOS
func (b IPv6) TOS() (uint8, uint32) { v := binary.BigEndian.Uint32(b[versTCFL:]) return uint8(v >> 20), v & 0xfffff }
go
func (b IPv6) TOS() (uint8, uint32) { v := binary.BigEndian.Uint32(b[versTCFL:]) return uint8(v >> 20), v & 0xfffff }
[ "func", "(", "b", "IPv6", ")", "TOS", "(", ")", "(", "uint8", ",", "uint32", ")", "{", "v", ":=", "binary", ".", "BigEndian", ".", "Uint32", "(", "b", "[", "versTCFL", ":", "]", ")", "\n", "return", "uint8", "(", "v", ">>", "20", ")", ",", "v...
// TOS returns the "traffic class" and "flow label" fields of the ipv6 header.
[ "TOS", "returns", "the", "traffic", "class", "and", "flow", "label", "fields", "of", "the", "ipv6", "header", "." ]
70ebca9c30730cf3887cdef3b85bb96ed7a97593
https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/header/ipv6.go#L129-L132
164,359
google/netstack
tcpip/header/ipv6.go
SetTOS
func (b IPv6) SetTOS(t uint8, l uint32) { vtf := (6 << 28) | (uint32(t) << 20) | (l & 0xfffff) binary.BigEndian.PutUint32(b[versTCFL:], vtf) }
go
func (b IPv6) SetTOS(t uint8, l uint32) { vtf := (6 << 28) | (uint32(t) << 20) | (l & 0xfffff) binary.BigEndian.PutUint32(b[versTCFL:], vtf) }
[ "func", "(", "b", "IPv6", ")", "SetTOS", "(", "t", "uint8", ",", "l", "uint32", ")", "{", "vtf", ":=", "(", "6", "<<", "28", ")", "|", "(", "uint32", "(", "t", ")", "<<", "20", ")", "|", "(", "l", "&", "0xfffff", ")", "\n", "binary", ".", ...
// SetTOS sets the "traffic class" and "flow label" fields of the ipv6 header.
[ "SetTOS", "sets", "the", "traffic", "class", "and", "flow", "label", "fields", "of", "the", "ipv6", "header", "." ]
70ebca9c30730cf3887cdef3b85bb96ed7a97593
https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/header/ipv6.go#L135-L138
164,360
google/netstack
tcpip/header/ipv6.go
SetPayloadLength
func (b IPv6) SetPayloadLength(payloadLength uint16) { binary.BigEndian.PutUint16(b[payloadLen:], payloadLength) }
go
func (b IPv6) SetPayloadLength(payloadLength uint16) { binary.BigEndian.PutUint16(b[payloadLen:], payloadLength) }
[ "func", "(", "b", "IPv6", ")", "SetPayloadLength", "(", "payloadLength", "uint16", ")", "{", "binary", ".", "BigEndian", ".", "PutUint16", "(", "b", "[", "payloadLen", ":", "]", ",", "payloadLength", ")", "\n", "}" ]
// SetPayloadLength sets the "payload length" field of the ipv6 header.
[ "SetPayloadLength", "sets", "the", "payload", "length", "field", "of", "the", "ipv6", "header", "." ]
70ebca9c30730cf3887cdef3b85bb96ed7a97593
https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/header/ipv6.go#L141-L143
164,361
google/netstack
tcpip/header/ipv6.go
SetSourceAddress
func (b IPv6) SetSourceAddress(addr tcpip.Address) { copy(b[v6SrcAddr:v6SrcAddr+IPv6AddressSize], addr) }
go
func (b IPv6) SetSourceAddress(addr tcpip.Address) { copy(b[v6SrcAddr:v6SrcAddr+IPv6AddressSize], addr) }
[ "func", "(", "b", "IPv6", ")", "SetSourceAddress", "(", "addr", "tcpip", ".", "Address", ")", "{", "copy", "(", "b", "[", "v6SrcAddr", ":", "v6SrcAddr", "+", "IPv6AddressSize", "]", ",", "addr", ")", "\n", "}" ]
// SetSourceAddress sets the "source address" field of the ipv6 header.
[ "SetSourceAddress", "sets", "the", "source", "address", "field", "of", "the", "ipv6", "header", "." ]
70ebca9c30730cf3887cdef3b85bb96ed7a97593
https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/header/ipv6.go#L146-L148
164,362
google/netstack
tcpip/header/ipv6.go
SetDestinationAddress
func (b IPv6) SetDestinationAddress(addr tcpip.Address) { copy(b[v6DstAddr:v6DstAddr+IPv6AddressSize], addr) }
go
func (b IPv6) SetDestinationAddress(addr tcpip.Address) { copy(b[v6DstAddr:v6DstAddr+IPv6AddressSize], addr) }
[ "func", "(", "b", "IPv6", ")", "SetDestinationAddress", "(", "addr", "tcpip", ".", "Address", ")", "{", "copy", "(", "b", "[", "v6DstAddr", ":", "v6DstAddr", "+", "IPv6AddressSize", "]", ",", "addr", ")", "\n", "}" ]
// SetDestinationAddress sets the "destination address" field of the ipv6 // header.
[ "SetDestinationAddress", "sets", "the", "destination", "address", "field", "of", "the", "ipv6", "header", "." ]
70ebca9c30730cf3887cdef3b85bb96ed7a97593
https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/header/ipv6.go#L152-L154
164,363
google/netstack
tcpip/header/ipv6.go
Encode
func (b IPv6) Encode(i *IPv6Fields) { b.SetTOS(i.TrafficClass, i.FlowLabel) b.SetPayloadLength(i.PayloadLength) b[nextHdr] = i.NextHeader b[hopLimit] = i.HopLimit copy(b[v6SrcAddr:v6SrcAddr+IPv6AddressSize], i.SrcAddr) copy(b[v6DstAddr:v6DstAddr+IPv6AddressSize], i.DstAddr) }
go
func (b IPv6) Encode(i *IPv6Fields) { b.SetTOS(i.TrafficClass, i.FlowLabel) b.SetPayloadLength(i.PayloadLength) b[nextHdr] = i.NextHeader b[hopLimit] = i.HopLimit copy(b[v6SrcAddr:v6SrcAddr+IPv6AddressSize], i.SrcAddr) copy(b[v6DstAddr:v6DstAddr+IPv6AddressSize], i.DstAddr) }
[ "func", "(", "b", "IPv6", ")", "Encode", "(", "i", "*", "IPv6Fields", ")", "{", "b", ".", "SetTOS", "(", "i", ".", "TrafficClass", ",", "i", ".", "FlowLabel", ")", "\n", "b", ".", "SetPayloadLength", "(", "i", ".", "PayloadLength", ")", "\n", "b", ...
// Encode encodes all the fields of the ipv6 header.
[ "Encode", "encodes", "all", "the", "fields", "of", "the", "ipv6", "header", "." ]
70ebca9c30730cf3887cdef3b85bb96ed7a97593
https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/header/ipv6.go#L167-L174
164,364
google/netstack
tcpip/header/ipv6.go
SolicitedNodeAddr
func SolicitedNodeAddr(addr tcpip.Address) tcpip.Address { const solicitedNodeMulticastPrefix = "\xff\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\xff" return solicitedNodeMulticastPrefix + addr[len(addr)-3:] }
go
func SolicitedNodeAddr(addr tcpip.Address) tcpip.Address { const solicitedNodeMulticastPrefix = "\xff\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\xff" return solicitedNodeMulticastPrefix + addr[len(addr)-3:] }
[ "func", "SolicitedNodeAddr", "(", "addr", "tcpip", ".", "Address", ")", "tcpip", ".", "Address", "{", "const", "solicitedNodeMulticastPrefix", "=", "\"", "\\xff", "\\x02", "\\x00", "\\x00", "\\x00", "\\x00", "\\x00", "\\x00", "\\x00", "\\x00", "\\x00", "\\x01", ...
// SolicitedNodeAddr computes the solicited-node multicast address. This is // used for NDP. Described in RFC 4291. The argument must be a full-length IPv6 // address.
[ "SolicitedNodeAddr", "computes", "the", "solicited", "-", "node", "multicast", "address", ".", "This", "is", "used", "for", "NDP", ".", "Described", "in", "RFC", "4291", ".", "The", "argument", "must", "be", "a", "full", "-", "length", "IPv6", "address", "...
70ebca9c30730cf3887cdef3b85bb96ed7a97593
https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/header/ipv6.go#L212-L215
164,365
google/netstack
tcpip/transport/udp/endpoint.go
Read
func (e *endpoint) Read(addr *tcpip.FullAddress) (buffer.View, tcpip.ControlMessages, *tcpip.Error) { e.rcvMu.Lock() if e.rcvList.Empty() { err := tcpip.ErrWouldBlock if e.rcvClosed { err = tcpip.ErrClosedForReceive } e.rcvMu.Unlock() return buffer.View{}, tcpip.ControlMessages{}, err } p := e.rcvList.Front() e.rcvList.Remove(p) e.rcvBufSize -= p.data.Size() e.rcvMu.Unlock() if addr != nil { *addr = p.senderAddress } return p.data.ToView(), tcpip.ControlMessages{HasTimestamp: true, Timestamp: p.timestamp}, nil }
go
func (e *endpoint) Read(addr *tcpip.FullAddress) (buffer.View, tcpip.ControlMessages, *tcpip.Error) { e.rcvMu.Lock() if e.rcvList.Empty() { err := tcpip.ErrWouldBlock if e.rcvClosed { err = tcpip.ErrClosedForReceive } e.rcvMu.Unlock() return buffer.View{}, tcpip.ControlMessages{}, err } p := e.rcvList.Front() e.rcvList.Remove(p) e.rcvBufSize -= p.data.Size() e.rcvMu.Unlock() if addr != nil { *addr = p.senderAddress } return p.data.ToView(), tcpip.ControlMessages{HasTimestamp: true, Timestamp: p.timestamp}, nil }
[ "func", "(", "e", "*", "endpoint", ")", "Read", "(", "addr", "*", "tcpip", ".", "FullAddress", ")", "(", "buffer", ".", "View", ",", "tcpip", ".", "ControlMessages", ",", "*", "tcpip", ".", "Error", ")", "{", "e", ".", "rcvMu", ".", "Lock", "(", ...
// Read reads data from the endpoint. This method does not block if // there is no data pending.
[ "Read", "reads", "data", "from", "the", "endpoint", ".", "This", "method", "does", "not", "block", "if", "there", "is", "no", "data", "pending", "." ]
70ebca9c30730cf3887cdef3b85bb96ed7a97593
https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/transport/udp/endpoint.go#L173-L196
164,366
google/netstack
tcpip/transport/udp/endpoint.go
prepareForWrite
func (e *endpoint) prepareForWrite(to *tcpip.FullAddress) (retry bool, err *tcpip.Error) { switch e.state { case stateInitial: case stateConnected: return false, nil case stateBound: if to == nil { return false, tcpip.ErrDestinationRequired } return false, nil default: return false, tcpip.ErrInvalidEndpointState } e.mu.RUnlock() defer e.mu.RLock() e.mu.Lock() defer e.mu.Unlock() // The state changed when we released the shared locked and re-acquired // it in exclusive mode. Try again. if e.state != stateInitial { return true, nil } // The state is still 'initial', so try to bind the endpoint. if err := e.bindLocked(tcpip.FullAddress{}); err != nil { return false, err } return true, nil }
go
func (e *endpoint) prepareForWrite(to *tcpip.FullAddress) (retry bool, err *tcpip.Error) { switch e.state { case stateInitial: case stateConnected: return false, nil case stateBound: if to == nil { return false, tcpip.ErrDestinationRequired } return false, nil default: return false, tcpip.ErrInvalidEndpointState } e.mu.RUnlock() defer e.mu.RLock() e.mu.Lock() defer e.mu.Unlock() // The state changed when we released the shared locked and re-acquired // it in exclusive mode. Try again. if e.state != stateInitial { return true, nil } // The state is still 'initial', so try to bind the endpoint. if err := e.bindLocked(tcpip.FullAddress{}); err != nil { return false, err } return true, nil }
[ "func", "(", "e", "*", "endpoint", ")", "prepareForWrite", "(", "to", "*", "tcpip", ".", "FullAddress", ")", "(", "retry", "bool", ",", "err", "*", "tcpip", ".", "Error", ")", "{", "switch", "e", ".", "state", "{", "case", "stateInitial", ":", "case"...
// prepareForWrite prepares the endpoint for sending data. In particular, it // binds it if it's still in the initial state. To do so, it must first // reacquire the mutex in exclusive mode. // // Returns true for retry if preparation should be retried.
[ "prepareForWrite", "prepares", "the", "endpoint", "for", "sending", "data", ".", "In", "particular", "it", "binds", "it", "if", "it", "s", "still", "in", "the", "initial", "state", ".", "To", "do", "so", "it", "must", "first", "reacquire", "the", "mutex", ...
70ebca9c30730cf3887cdef3b85bb96ed7a97593
https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/transport/udp/endpoint.go#L203-L236
164,367
google/netstack
tcpip/transport/udp/endpoint.go
connectRoute
func (e *endpoint) connectRoute(nicid tcpip.NICID, addr tcpip.FullAddress) (stack.Route, tcpip.NICID, tcpip.NetworkProtocolNumber, *tcpip.Error) { netProto, err := e.checkV4Mapped(&addr, false) if err != nil { return stack.Route{}, 0, 0, err } localAddr := e.id.LocalAddress if header.IsV4MulticastAddress(addr.Addr) || header.IsV6MulticastAddress(addr.Addr) { if nicid == 0 { nicid = e.multicastNICID } if localAddr == "" { localAddr = e.multicastAddr } } // Find a route to the desired destination. r, err := e.stack.FindRoute(nicid, localAddr, addr.Addr, netProto, e.multicastLoop) if err != nil { return stack.Route{}, 0, 0, err } return r, nicid, netProto, nil }
go
func (e *endpoint) connectRoute(nicid tcpip.NICID, addr tcpip.FullAddress) (stack.Route, tcpip.NICID, tcpip.NetworkProtocolNumber, *tcpip.Error) { netProto, err := e.checkV4Mapped(&addr, false) if err != nil { return stack.Route{}, 0, 0, err } localAddr := e.id.LocalAddress if header.IsV4MulticastAddress(addr.Addr) || header.IsV6MulticastAddress(addr.Addr) { if nicid == 0 { nicid = e.multicastNICID } if localAddr == "" { localAddr = e.multicastAddr } } // Find a route to the desired destination. r, err := e.stack.FindRoute(nicid, localAddr, addr.Addr, netProto, e.multicastLoop) if err != nil { return stack.Route{}, 0, 0, err } return r, nicid, netProto, nil }
[ "func", "(", "e", "*", "endpoint", ")", "connectRoute", "(", "nicid", "tcpip", ".", "NICID", ",", "addr", "tcpip", ".", "FullAddress", ")", "(", "stack", ".", "Route", ",", "tcpip", ".", "NICID", ",", "tcpip", ".", "NetworkProtocolNumber", ",", "*", "t...
// connectRoute establishes a route to the specified interface or the // configured multicast interface if no interface is specified and the // specified address is a multicast address.
[ "connectRoute", "establishes", "a", "route", "to", "the", "specified", "interface", "or", "the", "configured", "multicast", "interface", "if", "no", "interface", "is", "specified", "and", "the", "specified", "address", "is", "a", "multicast", "address", "." ]
70ebca9c30730cf3887cdef3b85bb96ed7a97593
https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/transport/udp/endpoint.go#L241-L263
164,368
google/netstack
tcpip/transport/udp/endpoint.go
Peek
func (e *endpoint) Peek([][]byte) (uintptr, tcpip.ControlMessages, *tcpip.Error) { return 0, tcpip.ControlMessages{}, nil }
go
func (e *endpoint) Peek([][]byte) (uintptr, tcpip.ControlMessages, *tcpip.Error) { return 0, tcpip.ControlMessages{}, nil }
[ "func", "(", "e", "*", "endpoint", ")", "Peek", "(", "[", "]", "[", "]", "byte", ")", "(", "uintptr", ",", "tcpip", ".", "ControlMessages", ",", "*", "tcpip", ".", "Error", ")", "{", "return", "0", ",", "tcpip", ".", "ControlMessages", "{", "}", ...
// Peek only returns data from a single datagram, so do nothing here.
[ "Peek", "only", "returns", "data", "from", "a", "single", "datagram", "so", "do", "nothing", "here", "." ]
70ebca9c30730cf3887cdef3b85bb96ed7a97593
https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/transport/udp/endpoint.go#L376-L378
164,369
google/netstack
tcpip/transport/udp/endpoint.go
sendUDP
func sendUDP(r *stack.Route, data buffer.VectorisedView, localPort, remotePort uint16, ttl uint8) *tcpip.Error { // Allocate a buffer for the UDP header. hdr := buffer.NewPrependable(header.UDPMinimumSize + int(r.MaxHeaderLength())) // Initialize the header. udp := header.UDP(hdr.Prepend(header.UDPMinimumSize)) length := uint16(hdr.UsedLength() + data.Size()) udp.Encode(&header.UDPFields{ SrcPort: localPort, DstPort: remotePort, Length: length, }) // Only calculate the checksum if offloading isn't supported. if r.Capabilities()&stack.CapabilityTXChecksumOffload == 0 { xsum := r.PseudoHeaderChecksum(ProtocolNumber, length) for _, v := range data.Views() { xsum = header.Checksum(v, xsum) } udp.SetChecksum(^udp.CalculateChecksum(xsum)) } // Track count of packets sent. r.Stats().UDP.PacketsSent.Increment() return r.WritePacket(nil /* gso */, hdr, data, ProtocolNumber, ttl) }
go
func sendUDP(r *stack.Route, data buffer.VectorisedView, localPort, remotePort uint16, ttl uint8) *tcpip.Error { // Allocate a buffer for the UDP header. hdr := buffer.NewPrependable(header.UDPMinimumSize + int(r.MaxHeaderLength())) // Initialize the header. udp := header.UDP(hdr.Prepend(header.UDPMinimumSize)) length := uint16(hdr.UsedLength() + data.Size()) udp.Encode(&header.UDPFields{ SrcPort: localPort, DstPort: remotePort, Length: length, }) // Only calculate the checksum if offloading isn't supported. if r.Capabilities()&stack.CapabilityTXChecksumOffload == 0 { xsum := r.PseudoHeaderChecksum(ProtocolNumber, length) for _, v := range data.Views() { xsum = header.Checksum(v, xsum) } udp.SetChecksum(^udp.CalculateChecksum(xsum)) } // Track count of packets sent. r.Stats().UDP.PacketsSent.Increment() return r.WritePacket(nil /* gso */, hdr, data, ProtocolNumber, ttl) }
[ "func", "sendUDP", "(", "r", "*", "stack", ".", "Route", ",", "data", "buffer", ".", "VectorisedView", ",", "localPort", ",", "remotePort", "uint16", ",", "ttl", "uint8", ")", "*", "tcpip", ".", "Error", "{", "// Allocate a buffer for the UDP header.", "hdr", ...
// sendUDP sends a UDP segment via the provided network endpoint and under the // provided identity.
[ "sendUDP", "sends", "a", "UDP", "segment", "via", "the", "provided", "network", "endpoint", "and", "under", "the", "provided", "identity", "." ]
70ebca9c30730cf3887cdef3b85bb96ed7a97593
https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/transport/udp/endpoint.go#L628-L655
164,370
google/netstack
tcpip/transport/udp/endpoint.go
GetLocalAddress
func (e *endpoint) GetLocalAddress() (tcpip.FullAddress, *tcpip.Error) { e.mu.RLock() defer e.mu.RUnlock() return tcpip.FullAddress{ NIC: e.regNICID, Addr: e.id.LocalAddress, Port: e.id.LocalPort, }, nil }
go
func (e *endpoint) GetLocalAddress() (tcpip.FullAddress, *tcpip.Error) { e.mu.RLock() defer e.mu.RUnlock() return tcpip.FullAddress{ NIC: e.regNICID, Addr: e.id.LocalAddress, Port: e.id.LocalPort, }, nil }
[ "func", "(", "e", "*", "endpoint", ")", "GetLocalAddress", "(", ")", "(", "tcpip", ".", "FullAddress", ",", "*", "tcpip", ".", "Error", ")", "{", "e", ".", "mu", ".", "RLock", "(", ")", "\n", "defer", "e", ".", "mu", ".", "RUnlock", "(", ")", "...
// GetLocalAddress returns the address to which the endpoint is bound.
[ "GetLocalAddress", "returns", "the", "address", "to", "which", "the", "endpoint", "is", "bound", "." ]
70ebca9c30730cf3887cdef3b85bb96ed7a97593
https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/transport/udp/endpoint.go#L896-L905
164,371
google/netstack
tcpip/transport/tcp/timer.go
init
func (t *timer) init(w *sleep.Waker) { t.state = timerStateDisabled // Initialize a runtime timer that will assert the waker, then // immediately stop it. t.timer = time.AfterFunc(time.Hour, func() { w.Assert() }) t.timer.Stop() }
go
func (t *timer) init(w *sleep.Waker) { t.state = timerStateDisabled // Initialize a runtime timer that will assert the waker, then // immediately stop it. t.timer = time.AfterFunc(time.Hour, func() { w.Assert() }) t.timer.Stop() }
[ "func", "(", "t", "*", "timer", ")", "init", "(", "w", "*", "sleep", ".", "Waker", ")", "{", "t", ".", "state", "=", "timerStateDisabled", "\n\n", "// Initialize a runtime timer that will assert the waker, then", "// immediately stop it.", "t", ".", "timer", "=", ...
// init initializes the timer. Once it expires, it the given waker will be // asserted.
[ "init", "initializes", "the", "timer", ".", "Once", "it", "expires", "it", "the", "given", "waker", "will", "be", "asserted", "." ]
70ebca9c30730cf3887cdef3b85bb96ed7a97593
https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/transport/tcp/timer.go#L74-L83
164,372
google/netstack
tcpip/transport/tcp/timer.go
enable
func (t *timer) enable(d time.Duration) { t.target = time.Now().Add(d) // Check if we need to set the runtime timer. if t.state == timerStateDisabled || t.target.Before(t.runtimeTarget) { t.runtimeTarget = t.target t.timer.Reset(d) } t.state = timerStateEnabled }
go
func (t *timer) enable(d time.Duration) { t.target = time.Now().Add(d) // Check if we need to set the runtime timer. if t.state == timerStateDisabled || t.target.Before(t.runtimeTarget) { t.runtimeTarget = t.target t.timer.Reset(d) } t.state = timerStateEnabled }
[ "func", "(", "t", "*", "timer", ")", "enable", "(", "d", "time", ".", "Duration", ")", "{", "t", ".", "target", "=", "time", ".", "Now", "(", ")", ".", "Add", "(", "d", ")", "\n\n", "// Check if we need to set the runtime timer.", "if", "t", ".", "st...
// enable enables the timer, programming the runtime timer if necessary.
[ "enable", "enables", "the", "timer", "programming", "the", "runtime", "timer", "if", "necessary", "." ]
70ebca9c30730cf3887cdef3b85bb96ed7a97593
https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/transport/tcp/timer.go#L131-L141
164,373
google/netstack
dhcp/server.go
NewServer
func NewServer(ctx context.Context, c conn, addrs []tcpip.Address, cfg Config) (*Server, error) { if cfg.ServerAddress == "" { return nil, fmt.Errorf("dhcp: server requires explicit server address") } s := &Server{ conn: c, addrs: addrs, cfg: cfg, cfgopts: cfg.encode(), broadcast: tcpip.FullAddress{ Addr: "\xff\xff\xff\xff", Port: ClientPort, }, handlers: make([]chan header, 8), leases: make(map[tcpip.LinkAddress]serverLease), } for i := 0; i < len(s.handlers); i++ { ch := make(chan header, 8) s.handlers[i] = ch go s.handler(ctx, ch) } go s.expirer(ctx) go s.reader(ctx) return s, nil }
go
func NewServer(ctx context.Context, c conn, addrs []tcpip.Address, cfg Config) (*Server, error) { if cfg.ServerAddress == "" { return nil, fmt.Errorf("dhcp: server requires explicit server address") } s := &Server{ conn: c, addrs: addrs, cfg: cfg, cfgopts: cfg.encode(), broadcast: tcpip.FullAddress{ Addr: "\xff\xff\xff\xff", Port: ClientPort, }, handlers: make([]chan header, 8), leases: make(map[tcpip.LinkAddress]serverLease), } for i := 0; i < len(s.handlers); i++ { ch := make(chan header, 8) s.handlers[i] = ch go s.handler(ctx, ch) } go s.expirer(ctx) go s.reader(ctx) return s, nil }
[ "func", "NewServer", "(", "ctx", "context", ".", "Context", ",", "c", "conn", ",", "addrs", "[", "]", "tcpip", ".", "Address", ",", "cfg", "Config", ")", "(", "*", "Server", ",", "error", ")", "{", "if", "cfg", ".", "ServerAddress", "==", "\"", "\"...
// NewServer creates a new DHCP server and begins serving. // The server continues serving until ctx is done.
[ "NewServer", "creates", "a", "new", "DHCP", "server", "and", "begins", "serving", ".", "The", "server", "continues", "serving", "until", "ctx", "is", "done", "." ]
70ebca9c30730cf3887cdef3b85bb96ed7a97593
https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/dhcp/server.go#L135-L162
164,374
google/netstack
dhcp/server.go
reader
func (s *Server) reader(ctx context.Context) { for { v, _, err := s.conn.Read() if err != nil { return } h := header(v) if !h.isValid() || h.op() != opRequest { continue } xid := h.xid() // Fan out the packet to a handler goroutine. // // Use a consistent handler for a given xid, so that // packets from a particular client are processed // in order. ch := s.handlers[int(xid)%len(s.handlers)] select { case <-ctx.Done(): return case ch <- h: default: // drop the packet } } }
go
func (s *Server) reader(ctx context.Context) { for { v, _, err := s.conn.Read() if err != nil { return } h := header(v) if !h.isValid() || h.op() != opRequest { continue } xid := h.xid() // Fan out the packet to a handler goroutine. // // Use a consistent handler for a given xid, so that // packets from a particular client are processed // in order. ch := s.handlers[int(xid)%len(s.handlers)] select { case <-ctx.Done(): return case ch <- h: default: // drop the packet } } }
[ "func", "(", "s", "*", "Server", ")", "reader", "(", "ctx", "context", ".", "Context", ")", "{", "for", "{", "v", ",", "_", ",", "err", ":=", "s", ".", "conn", ".", "Read", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", ...
// reader listens for all incoming DHCP packets and fans them out to // handling goroutines based on XID as session identifiers.
[ "reader", "listens", "for", "all", "incoming", "DHCP", "packets", "and", "fans", "them", "out", "to", "handling", "goroutines", "based", "on", "XID", "as", "session", "identifiers", "." ]
70ebca9c30730cf3887cdef3b85bb96ed7a97593
https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/dhcp/server.go#L186-L213
164,375
google/netstack
tcpip/network/fragmentation/fragmentation.go
Process
func (f *Fragmentation) Process(id uint32, first, last uint16, more bool, vv buffer.VectorisedView) (buffer.VectorisedView, bool) { f.mu.Lock() r, ok := f.reassemblers[id] if ok && r.tooOld(f.timeout) { // This is very likely to be an id-collision or someone performing a slow-rate attack. f.release(r) ok = false } if !ok { r = newReassembler(id) f.reassemblers[id] = r f.rList.PushFront(r) } f.mu.Unlock() res, done, consumed := r.process(first, last, more, vv) f.mu.Lock() f.size += consumed if done { f.release(r) } // Evict reassemblers if we are consuming more memory than highLimit until // we reach lowLimit. if f.size > f.highLimit { tail := f.rList.Back() for f.size > f.lowLimit && tail != nil { f.release(tail) tail = tail.Prev() } } f.mu.Unlock() return res, done }
go
func (f *Fragmentation) Process(id uint32, first, last uint16, more bool, vv buffer.VectorisedView) (buffer.VectorisedView, bool) { f.mu.Lock() r, ok := f.reassemblers[id] if ok && r.tooOld(f.timeout) { // This is very likely to be an id-collision or someone performing a slow-rate attack. f.release(r) ok = false } if !ok { r = newReassembler(id) f.reassemblers[id] = r f.rList.PushFront(r) } f.mu.Unlock() res, done, consumed := r.process(first, last, more, vv) f.mu.Lock() f.size += consumed if done { f.release(r) } // Evict reassemblers if we are consuming more memory than highLimit until // we reach lowLimit. if f.size > f.highLimit { tail := f.rList.Back() for f.size > f.lowLimit && tail != nil { f.release(tail) tail = tail.Prev() } } f.mu.Unlock() return res, done }
[ "func", "(", "f", "*", "Fragmentation", ")", "Process", "(", "id", "uint32", ",", "first", ",", "last", "uint16", ",", "more", "bool", ",", "vv", "buffer", ".", "VectorisedView", ")", "(", "buffer", ".", "VectorisedView", ",", "bool", ")", "{", "f", ...
// Process processes an incoming fragment beloning to an ID // and returns a complete packet when all the packets belonging to that ID have been received.
[ "Process", "processes", "an", "incoming", "fragment", "beloning", "to", "an", "ID", "and", "returns", "a", "complete", "packet", "when", "all", "the", "packets", "belonging", "to", "that", "ID", "have", "been", "received", "." ]
70ebca9c30730cf3887cdef3b85bb96ed7a97593
https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/network/fragmentation/fragmentation.go#L85-L118
164,376
google/netstack
tcpip/checker/checker.go
IPv6
func IPv6(t *testing.T, b []byte, checkers ...NetworkChecker) { t.Helper() ipv6 := header.IPv6(b) if !ipv6.IsValid(len(b)) { t.Error("Not a valid IPv6 packet") } for _, f := range checkers { f(t, []header.Network{ipv6}) } if t.Failed() { t.FailNow() } }
go
func IPv6(t *testing.T, b []byte, checkers ...NetworkChecker) { t.Helper() ipv6 := header.IPv6(b) if !ipv6.IsValid(len(b)) { t.Error("Not a valid IPv6 packet") } for _, f := range checkers { f(t, []header.Network{ipv6}) } if t.Failed() { t.FailNow() } }
[ "func", "IPv6", "(", "t", "*", "testing", ".", "T", ",", "b", "[", "]", "byte", ",", "checkers", "...", "NetworkChecker", ")", "{", "t", ".", "Helper", "(", ")", "\n\n", "ipv6", ":=", "header", ".", "IPv6", "(", "b", ")", "\n", "if", "!", "ipv6...
// IPv6 checks the validity and properties of the given IPv6 packet. The usage // is similar to IPv4.
[ "IPv6", "checks", "the", "validity", "and", "properties", "of", "the", "given", "IPv6", "packet", ".", "The", "usage", "is", "similar", "to", "IPv4", "." ]
70ebca9c30730cf3887cdef3b85bb96ed7a97593
https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/checker/checker.go#L65-L79
164,377
google/netstack
tcpip/checker/checker.go
SrcAddr
func SrcAddr(addr tcpip.Address) NetworkChecker { return func(t *testing.T, h []header.Network) { t.Helper() if a := h[0].SourceAddress(); a != addr { t.Errorf("Bad source address, got %v, want %v", a, addr) } } }
go
func SrcAddr(addr tcpip.Address) NetworkChecker { return func(t *testing.T, h []header.Network) { t.Helper() if a := h[0].SourceAddress(); a != addr { t.Errorf("Bad source address, got %v, want %v", a, addr) } } }
[ "func", "SrcAddr", "(", "addr", "tcpip", ".", "Address", ")", "NetworkChecker", "{", "return", "func", "(", "t", "*", "testing", ".", "T", ",", "h", "[", "]", "header", ".", "Network", ")", "{", "t", ".", "Helper", "(", ")", "\n\n", "if", "a", ":...
// SrcAddr creates a checker that checks the source address.
[ "SrcAddr", "creates", "a", "checker", "that", "checks", "the", "source", "address", "." ]
70ebca9c30730cf3887cdef3b85bb96ed7a97593
https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/checker/checker.go#L82-L90
164,378
google/netstack
tcpip/checker/checker.go
DstAddr
func DstAddr(addr tcpip.Address) NetworkChecker { return func(t *testing.T, h []header.Network) { t.Helper() if a := h[0].DestinationAddress(); a != addr { t.Errorf("Bad destination address, got %v, want %v", a, addr) } } }
go
func DstAddr(addr tcpip.Address) NetworkChecker { return func(t *testing.T, h []header.Network) { t.Helper() if a := h[0].DestinationAddress(); a != addr { t.Errorf("Bad destination address, got %v, want %v", a, addr) } } }
[ "func", "DstAddr", "(", "addr", "tcpip", ".", "Address", ")", "NetworkChecker", "{", "return", "func", "(", "t", "*", "testing", ".", "T", ",", "h", "[", "]", "header", ".", "Network", ")", "{", "t", ".", "Helper", "(", ")", "\n\n", "if", "a", ":...
// DstAddr creates a checker that checks the destination address.
[ "DstAddr", "creates", "a", "checker", "that", "checks", "the", "destination", "address", "." ]
70ebca9c30730cf3887cdef3b85bb96ed7a97593
https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/checker/checker.go#L93-L101
164,379
google/netstack
tcpip/checker/checker.go
PayloadLen
func PayloadLen(plen int) NetworkChecker { return func(t *testing.T, h []header.Network) { t.Helper() if l := len(h[0].Payload()); l != plen { t.Errorf("Bad payload length, got %v, want %v", l, plen) } } }
go
func PayloadLen(plen int) NetworkChecker { return func(t *testing.T, h []header.Network) { t.Helper() if l := len(h[0].Payload()); l != plen { t.Errorf("Bad payload length, got %v, want %v", l, plen) } } }
[ "func", "PayloadLen", "(", "plen", "int", ")", "NetworkChecker", "{", "return", "func", "(", "t", "*", "testing", ".", "T", ",", "h", "[", "]", "header", ".", "Network", ")", "{", "t", ".", "Helper", "(", ")", "\n\n", "if", "l", ":=", "len", "(",...
// PayloadLen creates a checker that checks the payload length.
[ "PayloadLen", "creates", "a", "checker", "that", "checks", "the", "payload", "length", "." ]
70ebca9c30730cf3887cdef3b85bb96ed7a97593
https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/checker/checker.go#L120-L128
164,380
google/netstack
tcpip/checker/checker.go
FragmentOffset
func FragmentOffset(offset uint16) NetworkChecker { return func(t *testing.T, h []header.Network) { t.Helper() // We only do this of IPv4 for now. switch ip := h[0].(type) { case header.IPv4: if v := ip.FragmentOffset(); v != offset { t.Errorf("Bad fragment offset, got %v, want %v", v, offset) } } } }
go
func FragmentOffset(offset uint16) NetworkChecker { return func(t *testing.T, h []header.Network) { t.Helper() // We only do this of IPv4 for now. switch ip := h[0].(type) { case header.IPv4: if v := ip.FragmentOffset(); v != offset { t.Errorf("Bad fragment offset, got %v, want %v", v, offset) } } } }
[ "func", "FragmentOffset", "(", "offset", "uint16", ")", "NetworkChecker", "{", "return", "func", "(", "t", "*", "testing", ".", "T", ",", "h", "[", "]", "header", ".", "Network", ")", "{", "t", ".", "Helper", "(", ")", "\n\n", "// We only do this of IPv4...
// FragmentOffset creates a checker that checks the FragmentOffset field.
[ "FragmentOffset", "creates", "a", "checker", "that", "checks", "the", "FragmentOffset", "field", "." ]
70ebca9c30730cf3887cdef3b85bb96ed7a97593
https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/checker/checker.go#L131-L143
164,381
google/netstack
tcpip/checker/checker.go
FragmentFlags
func FragmentFlags(flags uint8) NetworkChecker { return func(t *testing.T, h []header.Network) { t.Helper() // We only do this of IPv4 for now. switch ip := h[0].(type) { case header.IPv4: if v := ip.Flags(); v != flags { t.Errorf("Bad fragment offset, got %v, want %v", v, flags) } } } }
go
func FragmentFlags(flags uint8) NetworkChecker { return func(t *testing.T, h []header.Network) { t.Helper() // We only do this of IPv4 for now. switch ip := h[0].(type) { case header.IPv4: if v := ip.Flags(); v != flags { t.Errorf("Bad fragment offset, got %v, want %v", v, flags) } } } }
[ "func", "FragmentFlags", "(", "flags", "uint8", ")", "NetworkChecker", "{", "return", "func", "(", "t", "*", "testing", ".", "T", ",", "h", "[", "]", "header", ".", "Network", ")", "{", "t", ".", "Helper", "(", ")", "\n\n", "// We only do this of IPv4 fo...
// FragmentFlags creates a checker that checks the fragment flags field.
[ "FragmentFlags", "creates", "a", "checker", "that", "checks", "the", "fragment", "flags", "field", "." ]
70ebca9c30730cf3887cdef3b85bb96ed7a97593
https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/checker/checker.go#L146-L158
164,382
google/netstack
tcpip/checker/checker.go
TOS
func TOS(tos uint8, label uint32) NetworkChecker { return func(t *testing.T, h []header.Network) { t.Helper() if v, l := h[0].TOS(); v != tos || l != label { t.Errorf("Bad TOS, got (%v, %v), want (%v,%v)", v, l, tos, label) } } }
go
func TOS(tos uint8, label uint32) NetworkChecker { return func(t *testing.T, h []header.Network) { t.Helper() if v, l := h[0].TOS(); v != tos || l != label { t.Errorf("Bad TOS, got (%v, %v), want (%v,%v)", v, l, tos, label) } } }
[ "func", "TOS", "(", "tos", "uint8", ",", "label", "uint32", ")", "NetworkChecker", "{", "return", "func", "(", "t", "*", "testing", ".", "T", ",", "h", "[", "]", "header", ".", "Network", ")", "{", "t", ".", "Helper", "(", ")", "\n\n", "if", "v",...
// TOS creates a checker that checks the TOS field.
[ "TOS", "creates", "a", "checker", "that", "checks", "the", "TOS", "field", "." ]
70ebca9c30730cf3887cdef3b85bb96ed7a97593
https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/checker/checker.go#L161-L169
164,383
google/netstack
tcpip/checker/checker.go
Raw
func Raw(want []byte) NetworkChecker { return func(t *testing.T, h []header.Network) { t.Helper() if got := h[len(h)-1].Payload(); !reflect.DeepEqual(got, want) { t.Errorf("Wrong payload, got %v, want %v", got, want) } } }
go
func Raw(want []byte) NetworkChecker { return func(t *testing.T, h []header.Network) { t.Helper() if got := h[len(h)-1].Payload(); !reflect.DeepEqual(got, want) { t.Errorf("Wrong payload, got %v, want %v", got, want) } } }
[ "func", "Raw", "(", "want", "[", "]", "byte", ")", "NetworkChecker", "{", "return", "func", "(", "t", "*", "testing", ".", "T", ",", "h", "[", "]", "header", ".", "Network", ")", "{", "t", ".", "Helper", "(", ")", "\n\n", "if", "got", ":=", "h"...
// Raw creates a checker that checks the bytes of payload. // The checker always checks the payload of the last network header. // For instance, in case of IPv6 fragments, the payload that will be checked // is the one containing the actual data that the packet is carrying, without // the bytes added by the IPv6 fragmentation.
[ "Raw", "creates", "a", "checker", "that", "checks", "the", "bytes", "of", "payload", ".", "The", "checker", "always", "checks", "the", "payload", "of", "the", "last", "network", "header", ".", "For", "instance", "in", "case", "of", "IPv6", "fragments", "th...
70ebca9c30730cf3887cdef3b85bb96ed7a97593
https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/checker/checker.go#L176-L184
164,384
google/netstack
tcpip/checker/checker.go
IPv6Fragment
func IPv6Fragment(checkers ...NetworkChecker) NetworkChecker { return func(t *testing.T, h []header.Network) { t.Helper() if p := h[0].TransportProtocol(); p != header.IPv6FragmentHeader { t.Errorf("Bad protocol, got %v, want %v", p, header.UDPProtocolNumber) } ipv6Frag := header.IPv6Fragment(h[0].Payload()) if !ipv6Frag.IsValid() { t.Error("Not a valid IPv6 fragment") } for _, f := range checkers { f(t, []header.Network{h[0], ipv6Frag}) } if t.Failed() { t.FailNow() } } }
go
func IPv6Fragment(checkers ...NetworkChecker) NetworkChecker { return func(t *testing.T, h []header.Network) { t.Helper() if p := h[0].TransportProtocol(); p != header.IPv6FragmentHeader { t.Errorf("Bad protocol, got %v, want %v", p, header.UDPProtocolNumber) } ipv6Frag := header.IPv6Fragment(h[0].Payload()) if !ipv6Frag.IsValid() { t.Error("Not a valid IPv6 fragment") } for _, f := range checkers { f(t, []header.Network{h[0], ipv6Frag}) } if t.Failed() { t.FailNow() } } }
[ "func", "IPv6Fragment", "(", "checkers", "...", "NetworkChecker", ")", "NetworkChecker", "{", "return", "func", "(", "t", "*", "testing", ".", "T", ",", "h", "[", "]", "header", ".", "Network", ")", "{", "t", ".", "Helper", "(", ")", "\n\n", "if", "p...
// IPv6Fragment creates a checker that validates an IPv6 fragment.
[ "IPv6Fragment", "creates", "a", "checker", "that", "validates", "an", "IPv6", "fragment", "." ]
70ebca9c30730cf3887cdef3b85bb96ed7a97593
https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/checker/checker.go#L187-L207
164,385
google/netstack
tcpip/checker/checker.go
TCP
func TCP(checkers ...TransportChecker) NetworkChecker { return func(t *testing.T, h []header.Network) { t.Helper() first := h[0] last := h[len(h)-1] if p := last.TransportProtocol(); p != header.TCPProtocolNumber { t.Errorf("Bad protocol, got %v, want %v", p, header.TCPProtocolNumber) } // Verify the checksum. tcp := header.TCP(last.Payload()) l := uint16(len(tcp)) xsum := header.Checksum([]byte(first.SourceAddress()), 0) xsum = header.Checksum([]byte(first.DestinationAddress()), xsum) xsum = header.Checksum([]byte{0, byte(last.TransportProtocol())}, xsum) xsum = header.Checksum([]byte{byte(l >> 8), byte(l)}, xsum) xsum = header.Checksum(tcp, xsum) if xsum != 0 && xsum != 0xffff { t.Errorf("Bad checksum: 0x%x, checksum in segment: 0x%x", xsum, tcp.Checksum()) } // Run the transport checkers. for _, f := range checkers { f(t, tcp) } if t.Failed() { t.FailNow() } } }
go
func TCP(checkers ...TransportChecker) NetworkChecker { return func(t *testing.T, h []header.Network) { t.Helper() first := h[0] last := h[len(h)-1] if p := last.TransportProtocol(); p != header.TCPProtocolNumber { t.Errorf("Bad protocol, got %v, want %v", p, header.TCPProtocolNumber) } // Verify the checksum. tcp := header.TCP(last.Payload()) l := uint16(len(tcp)) xsum := header.Checksum([]byte(first.SourceAddress()), 0) xsum = header.Checksum([]byte(first.DestinationAddress()), xsum) xsum = header.Checksum([]byte{0, byte(last.TransportProtocol())}, xsum) xsum = header.Checksum([]byte{byte(l >> 8), byte(l)}, xsum) xsum = header.Checksum(tcp, xsum) if xsum != 0 && xsum != 0xffff { t.Errorf("Bad checksum: 0x%x, checksum in segment: 0x%x", xsum, tcp.Checksum()) } // Run the transport checkers. for _, f := range checkers { f(t, tcp) } if t.Failed() { t.FailNow() } } }
[ "func", "TCP", "(", "checkers", "...", "TransportChecker", ")", "NetworkChecker", "{", "return", "func", "(", "t", "*", "testing", ".", "T", ",", "h", "[", "]", "header", ".", "Network", ")", "{", "t", ".", "Helper", "(", ")", "\n\n", "first", ":=", ...
// TCP creates a checker that checks that the transport protocol is TCP and // potentially additional transport header fields.
[ "TCP", "creates", "a", "checker", "that", "checks", "that", "the", "transport", "protocol", "is", "TCP", "and", "potentially", "additional", "transport", "header", "fields", "." ]
70ebca9c30730cf3887cdef3b85bb96ed7a97593
https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/checker/checker.go#L211-L244
164,386
google/netstack
tcpip/checker/checker.go
UDP
func UDP(checkers ...TransportChecker) NetworkChecker { return func(t *testing.T, h []header.Network) { t.Helper() last := h[len(h)-1] if p := last.TransportProtocol(); p != header.UDPProtocolNumber { t.Errorf("Bad protocol, got %v, want %v", p, header.UDPProtocolNumber) } udp := header.UDP(last.Payload()) for _, f := range checkers { f(t, udp) } if t.Failed() { t.FailNow() } } }
go
func UDP(checkers ...TransportChecker) NetworkChecker { return func(t *testing.T, h []header.Network) { t.Helper() last := h[len(h)-1] if p := last.TransportProtocol(); p != header.UDPProtocolNumber { t.Errorf("Bad protocol, got %v, want %v", p, header.UDPProtocolNumber) } udp := header.UDP(last.Payload()) for _, f := range checkers { f(t, udp) } if t.Failed() { t.FailNow() } } }
[ "func", "UDP", "(", "checkers", "...", "TransportChecker", ")", "NetworkChecker", "{", "return", "func", "(", "t", "*", "testing", ".", "T", ",", "h", "[", "]", "header", ".", "Network", ")", "{", "t", ".", "Helper", "(", ")", "\n\n", "last", ":=", ...
// UDP creates a checker that checks that the transport protocol is UDP and // potentially additional transport header fields.
[ "UDP", "creates", "a", "checker", "that", "checks", "that", "the", "transport", "protocol", "is", "UDP", "and", "potentially", "additional", "transport", "header", "fields", "." ]
70ebca9c30730cf3887cdef3b85bb96ed7a97593
https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/checker/checker.go#L248-L266
164,387
google/netstack
tcpip/checker/checker.go
SrcPort
func SrcPort(port uint16) TransportChecker { return func(t *testing.T, h header.Transport) { t.Helper() if p := h.SourcePort(); p != port { t.Errorf("Bad source port, got %v, want %v", p, port) } } }
go
func SrcPort(port uint16) TransportChecker { return func(t *testing.T, h header.Transport) { t.Helper() if p := h.SourcePort(); p != port { t.Errorf("Bad source port, got %v, want %v", p, port) } } }
[ "func", "SrcPort", "(", "port", "uint16", ")", "TransportChecker", "{", "return", "func", "(", "t", "*", "testing", ".", "T", ",", "h", "header", ".", "Transport", ")", "{", "t", ".", "Helper", "(", ")", "\n\n", "if", "p", ":=", "h", ".", "SourcePo...
// SrcPort creates a checker that checks the source port.
[ "SrcPort", "creates", "a", "checker", "that", "checks", "the", "source", "port", "." ]
70ebca9c30730cf3887cdef3b85bb96ed7a97593
https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/checker/checker.go#L269-L277
164,388
google/netstack
tcpip/checker/checker.go
DstPort
func DstPort(port uint16) TransportChecker { return func(t *testing.T, h header.Transport) { if p := h.DestinationPort(); p != port { t.Errorf("Bad destination port, got %v, want %v", p, port) } } }
go
func DstPort(port uint16) TransportChecker { return func(t *testing.T, h header.Transport) { if p := h.DestinationPort(); p != port { t.Errorf("Bad destination port, got %v, want %v", p, port) } } }
[ "func", "DstPort", "(", "port", "uint16", ")", "TransportChecker", "{", "return", "func", "(", "t", "*", "testing", ".", "T", ",", "h", "header", ".", "Transport", ")", "{", "if", "p", ":=", "h", ".", "DestinationPort", "(", ")", ";", "p", "!=", "p...
// DstPort creates a checker that checks the destination port.
[ "DstPort", "creates", "a", "checker", "that", "checks", "the", "destination", "port", "." ]
70ebca9c30730cf3887cdef3b85bb96ed7a97593
https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/checker/checker.go#L280-L286
164,389
google/netstack
tcpip/checker/checker.go
SeqNum
func SeqNum(seq uint32) TransportChecker { return func(t *testing.T, h header.Transport) { t.Helper() tcp, ok := h.(header.TCP) if !ok { return } if s := tcp.SequenceNumber(); s != seq { t.Errorf("Bad sequence number, got %v, want %v", s, seq) } } }
go
func SeqNum(seq uint32) TransportChecker { return func(t *testing.T, h header.Transport) { t.Helper() tcp, ok := h.(header.TCP) if !ok { return } if s := tcp.SequenceNumber(); s != seq { t.Errorf("Bad sequence number, got %v, want %v", s, seq) } } }
[ "func", "SeqNum", "(", "seq", "uint32", ")", "TransportChecker", "{", "return", "func", "(", "t", "*", "testing", ".", "T", ",", "h", "header", ".", "Transport", ")", "{", "t", ".", "Helper", "(", ")", "\n\n", "tcp", ",", "ok", ":=", "h", ".", "(...
// SeqNum creates a checker that checks the sequence number.
[ "SeqNum", "creates", "a", "checker", "that", "checks", "the", "sequence", "number", "." ]
70ebca9c30730cf3887cdef3b85bb96ed7a97593
https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/checker/checker.go#L289-L302
164,390
google/netstack
tcpip/checker/checker.go
AckNum
func AckNum(seq uint32) TransportChecker { return func(t *testing.T, h header.Transport) { t.Helper() tcp, ok := h.(header.TCP) if !ok { return } if s := tcp.AckNumber(); s != seq { t.Errorf("Bad ack number, got %v, want %v", s, seq) } } }
go
func AckNum(seq uint32) TransportChecker { return func(t *testing.T, h header.Transport) { t.Helper() tcp, ok := h.(header.TCP) if !ok { return } if s := tcp.AckNumber(); s != seq { t.Errorf("Bad ack number, got %v, want %v", s, seq) } } }
[ "func", "AckNum", "(", "seq", "uint32", ")", "TransportChecker", "{", "return", "func", "(", "t", "*", "testing", ".", "T", ",", "h", "header", ".", "Transport", ")", "{", "t", ".", "Helper", "(", ")", "\n", "tcp", ",", "ok", ":=", "h", ".", "(",...
// AckNum creates a checker that checks the ack number.
[ "AckNum", "creates", "a", "checker", "that", "checks", "the", "ack", "number", "." ]
70ebca9c30730cf3887cdef3b85bb96ed7a97593
https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/checker/checker.go#L305-L317
164,391
google/netstack
tcpip/checker/checker.go
Window
func Window(window uint16) TransportChecker { return func(t *testing.T, h header.Transport) { tcp, ok := h.(header.TCP) if !ok { return } if w := tcp.WindowSize(); w != window { t.Errorf("Bad window, got 0x%x, want 0x%x", w, window) } } }
go
func Window(window uint16) TransportChecker { return func(t *testing.T, h header.Transport) { tcp, ok := h.(header.TCP) if !ok { return } if w := tcp.WindowSize(); w != window { t.Errorf("Bad window, got 0x%x, want 0x%x", w, window) } } }
[ "func", "Window", "(", "window", "uint16", ")", "TransportChecker", "{", "return", "func", "(", "t", "*", "testing", ".", "T", ",", "h", "header", ".", "Transport", ")", "{", "tcp", ",", "ok", ":=", "h", ".", "(", "header", ".", "TCP", ")", "\n", ...
// Window creates a checker that checks the tcp window.
[ "Window", "creates", "a", "checker", "that", "checks", "the", "tcp", "window", "." ]
70ebca9c30730cf3887cdef3b85bb96ed7a97593
https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/checker/checker.go#L320-L331
164,392
google/netstack
tcpip/checker/checker.go
TCPFlags
func TCPFlags(flags uint8) TransportChecker { return func(t *testing.T, h header.Transport) { t.Helper() tcp, ok := h.(header.TCP) if !ok { return } if f := tcp.Flags(); f != flags { t.Errorf("Bad flags, got 0x%x, want 0x%x", f, flags) } } }
go
func TCPFlags(flags uint8) TransportChecker { return func(t *testing.T, h header.Transport) { t.Helper() tcp, ok := h.(header.TCP) if !ok { return } if f := tcp.Flags(); f != flags { t.Errorf("Bad flags, got 0x%x, want 0x%x", f, flags) } } }
[ "func", "TCPFlags", "(", "flags", "uint8", ")", "TransportChecker", "{", "return", "func", "(", "t", "*", "testing", ".", "T", ",", "h", "header", ".", "Transport", ")", "{", "t", ".", "Helper", "(", ")", "\n\n", "tcp", ",", "ok", ":=", "h", ".", ...
// TCPFlags creates a checker that checks the tcp flags.
[ "TCPFlags", "creates", "a", "checker", "that", "checks", "the", "tcp", "flags", "." ]
70ebca9c30730cf3887cdef3b85bb96ed7a97593
https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/checker/checker.go#L334-L347
164,393
google/netstack
tcpip/checker/checker.go
TCPFlagsMatch
func TCPFlagsMatch(flags, mask uint8) TransportChecker { return func(t *testing.T, h header.Transport) { tcp, ok := h.(header.TCP) if !ok { return } if f := tcp.Flags(); (f & mask) != (flags & mask) { t.Errorf("Bad masked flags, got 0x%x, want 0x%x, mask 0x%x", f, flags, mask) } } }
go
func TCPFlagsMatch(flags, mask uint8) TransportChecker { return func(t *testing.T, h header.Transport) { tcp, ok := h.(header.TCP) if !ok { return } if f := tcp.Flags(); (f & mask) != (flags & mask) { t.Errorf("Bad masked flags, got 0x%x, want 0x%x, mask 0x%x", f, flags, mask) } } }
[ "func", "TCPFlagsMatch", "(", "flags", ",", "mask", "uint8", ")", "TransportChecker", "{", "return", "func", "(", "t", "*", "testing", ".", "T", ",", "h", "header", ".", "Transport", ")", "{", "tcp", ",", "ok", ":=", "h", ".", "(", "header", ".", "...
// TCPFlagsMatch creates a checker that checks that the tcp flags, masked by the // given mask, match the supplied flags.
[ "TCPFlagsMatch", "creates", "a", "checker", "that", "checks", "that", "the", "tcp", "flags", "masked", "by", "the", "given", "mask", "match", "the", "supplied", "flags", "." ]
70ebca9c30730cf3887cdef3b85bb96ed7a97593
https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/checker/checker.go#L351-L362
164,394
google/netstack
tcpip/checker/checker.go
TCPSACKBlockChecker
func TCPSACKBlockChecker(sackBlocks []header.SACKBlock) TransportChecker { return func(t *testing.T, h header.Transport) { t.Helper() tcp, ok := h.(header.TCP) if !ok { return } var gotSACKBlocks []header.SACKBlock opts := []byte(tcp.Options()) limit := len(opts) for i := 0; i < limit; { switch opts[i] { case header.TCPOptionEOL: i = limit case header.TCPOptionNOP: i++ case header.TCPOptionSACK: if i+2 > limit { // Malformed SACK block. t.Errorf("malformed SACK option in options: %v", opts) } sackOptionLen := int(opts[i+1]) if i+sackOptionLen > limit || (sackOptionLen-2)%8 != 0 { // Malformed SACK block. t.Errorf("malformed SACK option length in options: %v", opts) } numBlocks := sackOptionLen / 8 for j := 0; j < numBlocks; j++ { start := binary.BigEndian.Uint32(opts[i+2+j*8:]) end := binary.BigEndian.Uint32(opts[i+2+j*8+4:]) gotSACKBlocks = append(gotSACKBlocks, header.SACKBlock{ Start: seqnum.Value(start), End: seqnum.Value(end), }) } i += sackOptionLen default: // We don't recognize this option, just skip over it. if i+2 > limit { break } l := int(opts[i+1]) if l < 2 || i+l > limit { break } i += l } } if !reflect.DeepEqual(gotSACKBlocks, sackBlocks) { t.Errorf("SACKBlocks are not equal, got: %v, want: %v", gotSACKBlocks, sackBlocks) } } }
go
func TCPSACKBlockChecker(sackBlocks []header.SACKBlock) TransportChecker { return func(t *testing.T, h header.Transport) { t.Helper() tcp, ok := h.(header.TCP) if !ok { return } var gotSACKBlocks []header.SACKBlock opts := []byte(tcp.Options()) limit := len(opts) for i := 0; i < limit; { switch opts[i] { case header.TCPOptionEOL: i = limit case header.TCPOptionNOP: i++ case header.TCPOptionSACK: if i+2 > limit { // Malformed SACK block. t.Errorf("malformed SACK option in options: %v", opts) } sackOptionLen := int(opts[i+1]) if i+sackOptionLen > limit || (sackOptionLen-2)%8 != 0 { // Malformed SACK block. t.Errorf("malformed SACK option length in options: %v", opts) } numBlocks := sackOptionLen / 8 for j := 0; j < numBlocks; j++ { start := binary.BigEndian.Uint32(opts[i+2+j*8:]) end := binary.BigEndian.Uint32(opts[i+2+j*8+4:]) gotSACKBlocks = append(gotSACKBlocks, header.SACKBlock{ Start: seqnum.Value(start), End: seqnum.Value(end), }) } i += sackOptionLen default: // We don't recognize this option, just skip over it. if i+2 > limit { break } l := int(opts[i+1]) if l < 2 || i+l > limit { break } i += l } } if !reflect.DeepEqual(gotSACKBlocks, sackBlocks) { t.Errorf("SACKBlocks are not equal, got: %v, want: %v", gotSACKBlocks, sackBlocks) } } }
[ "func", "TCPSACKBlockChecker", "(", "sackBlocks", "[", "]", "header", ".", "SACKBlock", ")", "TransportChecker", "{", "return", "func", "(", "t", "*", "testing", ".", "T", ",", "h", "header", ".", "Transport", ")", "{", "t", ".", "Helper", "(", ")", "\...
// TCPSACKBlockChecker creates a checker that verifies that the segment does // contain the specified SACK blocks in the TCP options.
[ "TCPSACKBlockChecker", "creates", "a", "checker", "that", "verifies", "that", "the", "segment", "does", "contain", "the", "specified", "SACK", "blocks", "in", "the", "TCP", "options", "." ]
70ebca9c30730cf3887cdef3b85bb96ed7a97593
https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/checker/checker.go#L525-L579
164,395
google/netstack
tcpip/checker/checker.go
Payload
func Payload(want []byte) TransportChecker { return func(t *testing.T, h header.Transport) { if got := h.Payload(); !reflect.DeepEqual(got, want) { t.Errorf("Wrong payload, got %v, want %v", got, want) } } }
go
func Payload(want []byte) TransportChecker { return func(t *testing.T, h header.Transport) { if got := h.Payload(); !reflect.DeepEqual(got, want) { t.Errorf("Wrong payload, got %v, want %v", got, want) } } }
[ "func", "Payload", "(", "want", "[", "]", "byte", ")", "TransportChecker", "{", "return", "func", "(", "t", "*", "testing", ".", "T", ",", "h", "header", ".", "Transport", ")", "{", "if", "got", ":=", "h", ".", "Payload", "(", ")", ";", "!", "ref...
// Payload creates a checker that checks the payload.
[ "Payload", "creates", "a", "checker", "that", "checks", "the", "payload", "." ]
70ebca9c30730cf3887cdef3b85bb96ed7a97593
https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/checker/checker.go#L582-L588
164,396
google/netstack
tcpip/network/fragmentation/frag_heap.go
reassemble
func (h *fragHeap) reassemble() (buffer.VectorisedView, error) { curr := heap.Pop(h).(fragment) views := curr.vv.Views() size := curr.vv.Size() if curr.offset != 0 { return buffer.VectorisedView{}, fmt.Errorf("offset of the first packet is != 0 (%d)", curr.offset) } for h.Len() > 0 { curr := heap.Pop(h).(fragment) if int(curr.offset) < size { curr.vv.TrimFront(size - int(curr.offset)) } else if int(curr.offset) > size { return buffer.VectorisedView{}, fmt.Errorf("packet has a hole, expected offset %d, got %d", size, curr.offset) } size += curr.vv.Size() views = append(views, curr.vv.Views()...) } return buffer.NewVectorisedView(size, views), nil }
go
func (h *fragHeap) reassemble() (buffer.VectorisedView, error) { curr := heap.Pop(h).(fragment) views := curr.vv.Views() size := curr.vv.Size() if curr.offset != 0 { return buffer.VectorisedView{}, fmt.Errorf("offset of the first packet is != 0 (%d)", curr.offset) } for h.Len() > 0 { curr := heap.Pop(h).(fragment) if int(curr.offset) < size { curr.vv.TrimFront(size - int(curr.offset)) } else if int(curr.offset) > size { return buffer.VectorisedView{}, fmt.Errorf("packet has a hole, expected offset %d, got %d", size, curr.offset) } size += curr.vv.Size() views = append(views, curr.vv.Views()...) } return buffer.NewVectorisedView(size, views), nil }
[ "func", "(", "h", "*", "fragHeap", ")", "reassemble", "(", ")", "(", "buffer", ".", "VectorisedView", ",", "error", ")", "{", "curr", ":=", "heap", ".", "Pop", "(", "h", ")", ".", "(", "fragment", ")", "\n", "views", ":=", "curr", ".", "vv", ".",...
// reassamble empties the heap and returns a VectorisedView // containing a reassambled version of the fragments inside the heap.
[ "reassamble", "empties", "the", "heap", "and", "returns", "a", "VectorisedView", "containing", "a", "reassambled", "version", "of", "the", "fragments", "inside", "the", "heap", "." ]
70ebca9c30730cf3887cdef3b85bb96ed7a97593
https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/network/fragmentation/frag_heap.go#L57-L77
164,397
google/netstack
tcpip/network/ipv6/ipv6.go
HandlePacket
func (e *endpoint) HandlePacket(r *stack.Route, vv buffer.VectorisedView) { headerView := vv.First() h := header.IPv6(headerView) if !h.IsValid(vv.Size()) { return } vv.TrimFront(header.IPv6MinimumSize) vv.CapLength(int(h.PayloadLength())) p := h.TransportProtocol() if p == header.ICMPv6ProtocolNumber { e.handleICMP(r, headerView, vv) return } r.Stats().IP.PacketsDelivered.Increment() e.dispatcher.DeliverTransportPacket(r, p, headerView, vv) }
go
func (e *endpoint) HandlePacket(r *stack.Route, vv buffer.VectorisedView) { headerView := vv.First() h := header.IPv6(headerView) if !h.IsValid(vv.Size()) { return } vv.TrimFront(header.IPv6MinimumSize) vv.CapLength(int(h.PayloadLength())) p := h.TransportProtocol() if p == header.ICMPv6ProtocolNumber { e.handleICMP(r, headerView, vv) return } r.Stats().IP.PacketsDelivered.Increment() e.dispatcher.DeliverTransportPacket(r, p, headerView, vv) }
[ "func", "(", "e", "*", "endpoint", ")", "HandlePacket", "(", "r", "*", "stack", ".", "Route", ",", "vv", "buffer", ".", "VectorisedView", ")", "{", "headerView", ":=", "vv", ".", "First", "(", ")", "\n", "h", ":=", "header", ".", "IPv6", "(", "head...
// HandlePacket is called by the link layer when new ipv6 packets arrive for // this endpoint.
[ "HandlePacket", "is", "called", "by", "the", "link", "layer", "when", "new", "ipv6", "packets", "arrive", "for", "this", "endpoint", "." ]
70ebca9c30730cf3887cdef3b85bb96ed7a97593
https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/network/ipv6/ipv6.go#L123-L141
164,398
google/netstack
tcpip/network/ipv6/ipv6.go
NewEndpoint
func (p *protocol) NewEndpoint(nicid tcpip.NICID, addr tcpip.Address, linkAddrCache stack.LinkAddressCache, dispatcher stack.TransportDispatcher, linkEP stack.LinkEndpoint) (stack.NetworkEndpoint, *tcpip.Error) { return &endpoint{ nicid: nicid, id: stack.NetworkEndpointID{LocalAddress: addr}, linkEP: linkEP, linkAddrCache: linkAddrCache, dispatcher: dispatcher, }, nil }
go
func (p *protocol) NewEndpoint(nicid tcpip.NICID, addr tcpip.Address, linkAddrCache stack.LinkAddressCache, dispatcher stack.TransportDispatcher, linkEP stack.LinkEndpoint) (stack.NetworkEndpoint, *tcpip.Error) { return &endpoint{ nicid: nicid, id: stack.NetworkEndpointID{LocalAddress: addr}, linkEP: linkEP, linkAddrCache: linkAddrCache, dispatcher: dispatcher, }, nil }
[ "func", "(", "p", "*", "protocol", ")", "NewEndpoint", "(", "nicid", "tcpip", ".", "NICID", ",", "addr", "tcpip", ".", "Address", ",", "linkAddrCache", "stack", ".", "LinkAddressCache", ",", "dispatcher", "stack", ".", "TransportDispatcher", ",", "linkEP", "...
// NewEndpoint creates a new ipv6 endpoint.
[ "NewEndpoint", "creates", "a", "new", "ipv6", "endpoint", "." ]
70ebca9c30730cf3887cdef3b85bb96ed7a97593
https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/network/ipv6/ipv6.go#L173-L181
164,399
google/netstack
tcpip/header/eth.go
SourceAddress
func (b Ethernet) SourceAddress() tcpip.LinkAddress { return tcpip.LinkAddress(b[srcMAC:][:EthernetAddressSize]) }
go
func (b Ethernet) SourceAddress() tcpip.LinkAddress { return tcpip.LinkAddress(b[srcMAC:][:EthernetAddressSize]) }
[ "func", "(", "b", "Ethernet", ")", "SourceAddress", "(", ")", "tcpip", ".", "LinkAddress", "{", "return", "tcpip", ".", "LinkAddress", "(", "b", "[", "srcMAC", ":", "]", "[", ":", "EthernetAddressSize", "]", ")", "\n", "}" ]
// SourceAddress returns the "MAC source" field of the ethernet frame header.
[ "SourceAddress", "returns", "the", "MAC", "source", "field", "of", "the", "ethernet", "frame", "header", "." ]
70ebca9c30730cf3887cdef3b85bb96ed7a97593
https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/header/eth.go#L54-L56