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
sequence
docstring
stringlengths
6
2.61k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
85
252
partition
stringclasses
1 value
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", "(", "d", ".", "c", ",", "d", ",", "d", ".", "w", ",", "Event", "{", "Name", ":", "eventNameDockCmdShow", ",", "TargetID", ":", "d", ".", "id", "}", ",", "eventNameDockEventShown", ")", "\n", "return", "\n", "}" ]
// Show shows the dock
[ "Show", "shows", "the", "dock" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/dock.go#L105-L111
train
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", "// No need to disembed", "if", "_", ",", "err", "=", "os", ".", "Stat", "(", "dst", ")", ";", "err", "!=", "nil", "&&", "!", "os", ".", "IsNotExist", "(", "err", ")", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ",", "dst", ")", "\n", "}", "else", "if", "err", "==", "nil", "{", "astilog", ".", "Debugf", "(", "\"", "\"", ",", "dst", ")", "\n", "return", "\n", "}", "\n", "err", "=", "nil", "\n\n", "// Clean up on error", "defer", "func", "(", "err", "*", "error", ")", "{", "if", "*", "err", "!=", "nil", "||", "ctx", ".", "Err", "(", ")", "!=", "nil", "{", "astilog", ".", "Debugf", "(", "\"", "\"", ",", "dst", ")", "\n", "os", ".", "Remove", "(", "dst", ")", "\n", "}", "\n", "}", "(", "&", "err", ")", "\n\n", "// Make sure directory exists", "var", "dirPath", "=", "filepath", ".", "Dir", "(", "dst", ")", "\n", "astilog", ".", "Debugf", "(", "\"", "\"", ",", "dirPath", ")", "\n", "if", "err", "=", "os", ".", "MkdirAll", "(", "dirPath", ",", "0755", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ",", "dirPath", ")", "\n", "}", "\n\n", "// Create dst", "var", "f", "*", "os", ".", "File", "\n", "astilog", ".", "Debugf", "(", "\"", "\"", ",", "dst", ")", "\n", "if", "f", ",", "err", "=", "os", ".", "Create", "(", "dst", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ",", "dst", ")", "\n", "}", "\n", "defer", "f", ".", "Close", "(", ")", "\n\n", "// Disembed", "var", "b", "[", "]", "byte", "\n", "astilog", ".", "Debugf", "(", "\"", "\"", ",", "src", ")", "\n", "if", "b", ",", "err", "=", "d", "(", "src", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ",", "src", ")", "\n", "}", "\n\n", "// Copy", "astilog", ".", "Debugf", "(", "\"", "\"", ",", "dst", ")", "\n", "if", "_", ",", "err", "=", "astiio", ".", "Copy", "(", "ctx", ",", "bytes", ".", "NewReader", "(", "b", ")", ",", "f", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ",", "dst", ")", "\n", "}", "\n", "return", "\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
train
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", "(", ")", "\n", "defer", "cancel", "(", ")", "\n", "l", ".", "On", "(", "eventNameDone", ",", "func", "(", "i", "Event", ")", "(", "deleteListener", "bool", ")", "{", "e", "=", "i", "\n", "cancel", "(", ")", "\n", "return", "true", "\n", "}", ")", "\n", "fn", "(", ")", "\n", "<-", "ctx", ".", "Done", "(", ")", "\n", "return", "\n", "}" ]
// 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
train
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", "=", "synchronousFunc", "(", "c", ",", "l", ",", "func", "(", ")", "{", "if", "err", "=", "w", ".", "write", "(", "i", ")", ";", "err", "!=", "nil", "{", "err", "=", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ",", "i", ")", "\n", "return", "\n", "}", "\n", "return", "\n", "}", ",", "eventNameDone", ")", "\n", "return", "\n", "}" ]
// 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
train
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", "(", "i", ".", "i", ")", "\n", "}" ]
// 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
train
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", ",", "}", "\n", "}" ]
// newReader creates a new reader
[ "newReader", "creates", "a", "new", "reader" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/reader.go#L22-L28
train
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", "(", ")", ")", ",", "\"", "\"", ")", "\n", "}" ]
// 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
train
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", "{", "return", "\n", "}", "\n\n", "// Read next line", "var", "b", "[", "]", "byte", "\n", "var", "err", "error", "\n", "if", "b", ",", "err", "=", "reader", ".", "ReadBytes", "(", "'\\n'", ")", ";", "err", "!=", "nil", "{", "if", "!", "r", ".", "isEOFErr", "(", "err", ")", "{", "astilog", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "continue", "\n", "}", "\n", "return", "\n", "}", "\n", "b", "=", "bytes", ".", "TrimSpace", "(", "b", ")", "\n", "astilog", ".", "Debugf", "(", "\"", "\"", ",", "b", ")", "\n\n", "// Unmarshal", "var", "e", "Event", "\n", "if", "err", "=", "json", ".", "Unmarshal", "(", "b", ",", "&", "e", ")", ";", "err", "!=", "nil", "{", "astilog", ".", "Errorf", "(", "\"", "\"", ",", "err", ",", "b", ")", "\n", "continue", "\n", "}", "\n\n", "// Dispatch", "r", ".", "d", ".", "dispatch", "(", "e", ")", "\n", "}", "\n", "}" ]
// read reads from stdout
[ "read", "reads", "from", "stdout" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/reader.go#L42-L73
train
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", "_", ",", "ok", ":=", "d", ".", "l", "[", "targetID", "]", ";", "!", "ok", "{", "d", ".", "l", "[", "targetID", "]", "=", "make", "(", "map", "[", "string", "]", "map", "[", "int", "]", "Listener", ")", "\n", "}", "\n", "if", "_", ",", "ok", ":=", "d", ".", "l", "[", "targetID", "]", "[", "eventName", "]", ";", "!", "ok", "{", "d", ".", "l", "[", "targetID", "]", "[", "eventName", "]", "=", "make", "(", "map", "[", "int", "]", "Listener", ")", "\n", "}", "\n", "d", ".", "id", "++", "\n", "d", ".", "l", "[", "targetID", "]", "[", "eventName", "]", "[", "d", ".", "id", "]", "=", "l", "\n", "}" ]
// addListener adds a listener
[ "addListener", "adds", "a", "listener" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/dispatcher.go#L31-L42
train
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", "_", ",", "ok", ":=", "d", ".", "l", "[", "targetID", "]", ";", "!", "ok", "{", "return", "\n", "}", "\n", "if", "_", ",", "ok", ":=", "d", ".", "l", "[", "targetID", "]", "[", "eventName", "]", ";", "!", "ok", "{", "return", "\n", "}", "\n", "delete", "(", "d", ".", "l", "[", "targetID", "]", "[", "eventName", "]", ",", "id", ")", "\n", "}" ]
// delListener delete a specific listener
[ "delListener", "delete", "a", "specific", "listener" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/dispatcher.go#L45-L55
train
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", ".", "listeners", "(", "e", ".", "TargetID", ",", "e", ".", "Name", ")", "{", "if", "l", "(", "e", ")", "{", "d", ".", "delListener", "(", "e", ".", "TargetID", ",", "e", ".", "Name", ",", "id", ")", "\n", "}", "\n", "}", "\n", "}", "(", ")", "\n", "}" ]
// Dispatch dispatches an event
[ "Dispatch", "dispatches", "an", "event" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/dispatcher.go#L58-L67
train
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", "(", ")", "\n", "l", "=", "map", "[", "int", "]", "Listener", "{", "}", "\n", "if", "_", ",", "ok", ":=", "d", ".", "l", "[", "targetID", "]", ";", "!", "ok", "{", "return", "\n", "}", "\n", "if", "_", ",", "ok", ":=", "d", ".", "l", "[", "targetID", "]", "[", "eventName", "]", ";", "!", "ok", "{", "return", "\n", "}", "\n", "for", "k", ",", "v", ":=", "range", "d", ".", "l", "[", "targetID", "]", "[", "eventName", "]", "{", "l", "[", "k", "]", "=", "v", "\n", "}", "\n", "return", "\n", "}" ]
// 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
train
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", "*", "writer", ")", "(", "m", "*", "MenuItem", ")", "{", "m", "=", "&", "MenuItem", "{", "o", ":", "o", ",", "object", ":", "newObject", "(", "parentCtx", ",", "c", ",", "d", ",", "i", ",", "w", ",", "i", ".", "new", "(", ")", ")", ",", "rootID", ":", "rootID", ",", "}", "\n", "if", "o", ".", "OnClick", "!=", "nil", "{", "m", ".", "On", "(", "EventNameMenuItemEventClicked", ",", "o", ".", "OnClick", ")", "\n", "}", "\n", "if", "len", "(", "o", ".", "SubMenu", ")", ">", "0", "{", "m", ".", "s", "=", "&", "SubMenu", "{", "newSubMenu", "(", "parentCtx", ",", "rootID", ",", "o", ".", "SubMenu", ",", "c", ",", "d", ",", "i", ",", "w", ")", "}", "\n", "}", "\n", "return", "\n", "}" ]
// 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
train
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", ",", "}", "\n", "if", "i", ".", "s", "!=", "nil", "{", "e", ".", "SubMenu", "=", "i", ".", "s", ".", "toEvent", "(", ")", "\n", "}", "\n", "return", "\n", "}" ]
// 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
train
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", ".", "Checked", "=", "PtrBool", "(", "checked", ")", "\n", "_", ",", "err", "=", "synchronousEvent", "(", "i", ".", "c", ",", "i", ",", "i", ".", "w", ",", "Event", "{", "Name", ":", "EventNameMenuItemCmdSetChecked", ",", "TargetID", ":", "i", ".", "id", ",", "MenuItemOptions", ":", "&", "MenuItemOptions", "{", "Checked", ":", "i", ".", "o", ".", "Checked", "}", "}", ",", "EventNameMenuItemEventCheckedSet", ")", "\n", "return", "\n", "}" ]
// SetChecked sets the checked attribute
[ "SetChecked", "sets", "the", "checked", "attribute" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/menu_item.go#L131-L138
train
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", ".", "Enabled", "=", "PtrBool", "(", "enabled", ")", "\n", "_", ",", "err", "=", "synchronousEvent", "(", "i", ".", "c", ",", "i", ",", "i", ".", "w", ",", "Event", "{", "Name", ":", "EventNameMenuItemCmdSetEnabled", ",", "TargetID", ":", "i", ".", "id", ",", "MenuItemOptions", ":", "&", "MenuItemOptions", "{", "Enabled", ":", "i", ".", "o", ".", "Enabled", "}", "}", ",", "EventNameMenuItemEventEnabledSet", ")", "\n", "return", "\n", "}" ]
// SetEnabled sets the enabled attribute
[ "SetEnabled", "sets", "the", "enabled", "attribute" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/menu_item.go#L141-L148
train
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", ".", "Label", "=", "PtrStr", "(", "label", ")", "\n", "_", ",", "err", "=", "synchronousEvent", "(", "i", ".", "c", ",", "i", ",", "i", ".", "w", ",", "Event", "{", "Name", ":", "EventNameMenuItemCmdSetLabel", ",", "TargetID", ":", "i", ".", "id", ",", "MenuItemOptions", ":", "&", "MenuItemOptions", "{", "Label", ":", "i", ".", "o", ".", "Label", "}", "}", ",", "EventNameMenuItemEventLabelSet", ")", "\n", "return", "\n", "}" ]
// SetLabel sets the label attribute
[ "SetLabel", "sets", "the", "label", "attribute" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/menu_item.go#L151-L158
train
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", ".", "Visible", "=", "PtrBool", "(", "visible", ")", "\n", "_", ",", "err", "=", "synchronousEvent", "(", "i", ".", "c", ",", "i", ",", "i", ".", "w", ",", "Event", "{", "Name", ":", "EventNameMenuItemCmdSetVisible", ",", "TargetID", ":", "i", ".", "id", ",", "MenuItemOptions", ":", "&", "MenuItemOptions", "{", "Visible", ":", "i", ".", "o", ".", "Visible", "}", "}", ",", "EventNameMenuItemEventVisibleSet", ")", "\n", "return", "\n", "}" ]
// SetVisible sets the visible attribute
[ "SetVisible", "sets", "the", "visible", "attribute" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/menu_item.go#L161-L168
train
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", ".", "Y", "}", ",", "Size", ":", "Size", "{", "Height", ":", "*", "d", ".", "o", ".", "Bounds", ".", "Height", ",", "Width", ":", "*", "d", ".", "o", ".", "Bounds", ".", "Width", "}", ",", "}", "\n", "}" ]
// Bounds returns the display bounds
[ "Bounds", "returns", "the", "display", "bounds" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/display.go#L34-L39
train
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
train
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", "}", "\n", "}" ]
// 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
train
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", ")", "(", "w", "*", "Window", ",", "err", "error", ")", "{", "// Init", "w", "=", "&", "Window", "{", "callbackIdentifier", ":", "newIdentifier", "(", ")", ",", "o", ":", "wo", ",", "object", ":", "newObject", "(", "nil", ",", "c", ",", "d", ",", "i", ",", "wrt", ",", "i", ".", "new", "(", ")", ")", ",", "}", "\n", "w", ".", "Session", "=", "newSession", "(", "w", ".", "ctx", ",", "c", ",", "d", ",", "i", ",", "wrt", ")", "\n\n", "// Check app details", "if", "wo", ".", "Icon", "==", "nil", "&&", "p", ".", "AppIconDefaultSrc", "(", ")", "!=", "\"", "\"", "{", "wo", ".", "Icon", "=", "PtrStr", "(", "p", ".", "AppIconDefaultSrc", "(", ")", ")", "\n", "}", "\n", "if", "wo", ".", "Title", "==", "nil", "&&", "o", ".", "AppName", "!=", "\"", "\"", "{", "wo", ".", "Title", "=", "PtrStr", "(", "o", ".", "AppName", ")", "\n", "}", "\n\n", "// Make sure the window's context is cancelled once the closed event is received", "w", ".", "On", "(", "EventNameWindowEventClosed", ",", "func", "(", "e", "Event", ")", "(", "deleteListener", "bool", ")", "{", "w", ".", "cancel", "(", ")", "\n", "return", "true", "\n", "}", ")", "\n\n", "// Show", "w", ".", "On", "(", "EventNameWindowEventHide", ",", "func", "(", "e", "Event", ")", "(", "deleteListener", "bool", ")", "{", "w", ".", "m", ".", "Lock", "(", ")", "\n", "defer", "w", ".", "m", ".", "Unlock", "(", ")", "\n", "w", ".", "o", ".", "Show", "=", "PtrBool", "(", "false", ")", "\n", "return", "\n", "}", ")", "\n", "w", ".", "On", "(", "EventNameWindowEventShow", ",", "func", "(", "e", "Event", ")", "(", "deleteListener", "bool", ")", "{", "w", ".", "m", ".", "Lock", "(", ")", "\n", "defer", "w", ".", "m", ".", "Unlock", "(", ")", "\n", "w", ".", "o", ".", "Show", "=", "PtrBool", "(", "true", ")", "\n", "return", "\n", "}", ")", "\n\n", "// Parse url", "if", "w", ".", "url", ",", "err", "=", "astiurl", ".", "Parse", "(", "url", ")", ";", "err", "!=", "nil", "{", "err", "=", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ",", "url", ")", "\n", "return", "\n", "}", "\n", "return", "\n", "}" ]
// newWindow creates a new window
[ "newWindow", "creates", "a", "new", "window" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/window.go#L196-L239
train
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", ".", "i", ",", "w", ".", "w", ")", "\n", "}" ]
// 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
train
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", "(", "w", ".", "c", ",", "w", ",", "w", ".", "w", ",", "Event", "{", "Name", ":", "EventNameWindowCmdBlur", ",", "TargetID", ":", "w", ".", "id", "}", ",", "EventNameWindowEventBlur", ")", "\n", "return", "\n", "}" ]
// Blur blurs the window
[ "Blur", "blurs", "the", "window" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/window.go#L247-L253
train
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", "(", "w", ".", "c", ",", "w", ",", "w", ".", "w", ",", "Event", "{", "Name", ":", "EventNameWindowCmdCenter", ",", "TargetID", ":", "w", ".", "id", "}", ",", "EventNameWindowEventMove", ")", "\n", "return", "\n", "}" ]
// Center centers the window
[ "Center", "centers", "the", "window" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/window.go#L256-L262
train
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", "(", "w", ".", "c", ",", "w", ",", "w", ".", "w", ",", "Event", "{", "Name", ":", "EventNameWindowCmdClose", ",", "TargetID", ":", "w", ".", "id", "}", ",", "EventNameWindowEventClosed", ")", "\n", "return", "\n", "}" ]
// Close closes the window
[ "Close", "closes", "the", "window" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/window.go#L265-L271
train
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", "(", "Event", "{", "Name", ":", "EventNameWindowCmdWebContentsCloseDevTools", ",", "TargetID", ":", "w", ".", "id", "}", ")", "\n", "}" ]
// CloseDevTools closes the dev tools
[ "CloseDevTools", "closes", "the", "dev", "tools" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/window.go#L274-L279
train
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", "(", "w", ".", "c", ",", "w", ",", "w", ".", "w", ",", "Event", "{", "Name", ":", "EventNameWindowCmdCreate", ",", "SessionID", ":", "w", ".", "Session", ".", "id", ",", "TargetID", ":", "w", ".", "id", ",", "URL", ":", "w", ".", "url", ".", "String", "(", ")", ",", "WindowOptions", ":", "w", ".", "o", "}", ",", "EventNameWindowEventDidFinishLoad", ")", "\n", "return", "\n", "}" ]
// 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
train
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", "(", "w", ".", "c", ",", "w", ",", "w", ".", "w", ",", "Event", "{", "Name", ":", "EventNameWindowCmdDestroy", ",", "TargetID", ":", "w", ".", "id", "}", ",", "EventNameWindowEventClosed", ")", "\n", "return", "\n", "}" ]
// Destroy destroys the window
[ "Destroy", "destroys", "the", "window" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/window.go#L293-L299
train
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", "(", "w", ".", "c", ",", "w", ",", "w", ".", "w", ",", "Event", "{", "Name", ":", "EventNameWindowCmdFocus", ",", "TargetID", ":", "w", ".", "id", "}", ",", "EventNameWindowEventFocus", ")", "\n", "return", "\n", "}" ]
// Focus focuses on the window
[ "Focus", "focuses", "on", "the", "window" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/window.go#L302-L308
train
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", "(", "w", ".", "c", ",", "w", ",", "w", ".", "w", ",", "Event", "{", "Name", ":", "EventNameWindowCmdHide", ",", "TargetID", ":", "w", ".", "id", "}", ",", "EventNameWindowEventHide", ")", "\n", "return", "\n", "}" ]
// Hide hides the window
[ "Hide", "hides", "the", "window" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/window.go#L311-L317
train
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", "defer", "w", ".", "m", ".", "Unlock", "(", ")", "\n", "return", "w", ".", "o", ".", "Show", "!=", "nil", "&&", "*", "w", ".", "o", ".", "Show", "\n", "}" ]
// 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
train
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", ".", "write", "(", "Event", "{", "Message", ":", "newEventMessage", "(", "message", ")", ",", "Name", ":", "EventNameWindowCmdLog", ",", "TargetID", ":", "w", ".", "id", "}", ")", "\n", "}" ]
// 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
train
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", "(", "w", ".", "c", ",", "w", ",", "w", ".", "w", ",", "Event", "{", "Name", ":", "EventNameWindowCmdMaximize", ",", "TargetID", ":", "w", ".", "id", "}", ",", "EventNameWindowEventMaximize", ")", "\n", "return", "\n", "}" ]
// Maximize maximizes the window
[ "Maximize", "maximizes", "the", "window" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/window.go#L338-L344
train
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", "(", "w", ".", "c", ",", "w", ",", "w", ".", "w", ",", "Event", "{", "Name", ":", "EventNameWindowCmdMinimize", ",", "TargetID", ":", "w", ".", "id", "}", ",", "EventNameWindowEventMinimize", ")", "\n", "return", "\n", "}" ]
// Minimize minimizes the window
[ "Minimize", "minimizes", "the", "window" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/window.go#L347-L353
train
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", ".", "Lock", "(", ")", "\n", "w", ".", "o", ".", "X", "=", "PtrInt", "(", "x", ")", "\n", "w", ".", "o", ".", "Y", "=", "PtrInt", "(", "y", ")", "\n", "w", ".", "m", ".", "Unlock", "(", ")", "\n", "_", ",", "err", "=", "synchronousEvent", "(", "w", ".", "c", ",", "w", ",", "w", ".", "w", ",", "Event", "{", "Name", ":", "EventNameWindowCmdMove", ",", "TargetID", ":", "w", ".", "id", ",", "WindowOptions", ":", "&", "WindowOptions", "{", "X", ":", "PtrInt", "(", "x", ")", ",", "Y", ":", "PtrInt", "(", "y", ")", "}", "}", ",", "EventNameWindowEventMove", ")", "\n", "return", "\n", "}" ]
// Move moves the window
[ "Move", "moves", "the", "window" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/window.go#L356-L366
train
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", "(", ")", ".", "Y", "+", "y", ")", "\n", "}" ]
// 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
train
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", ")", "(", "deleteListener", "bool", ")", "{", "v", ":=", "l", "(", "i", ".", "Message", ")", "\n", "if", "len", "(", "i", ".", "CallbackID", ")", ">", "0", "{", "o", ":=", "Event", "{", "CallbackID", ":", "i", ".", "CallbackID", ",", "Name", ":", "eventNameWindowCmdMessageCallback", ",", "TargetID", ":", "w", ".", "id", "}", "\n", "if", "v", "!=", "nil", "{", "o", ".", "Message", "=", "newEventMessage", "(", "v", ")", "\n", "}", "\n", "if", "err", ":=", "w", ".", "w", ".", "write", "(", "o", ")", ";", "err", "!=", "nil", "{", "astilog", ".", "Error", "(", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", ")", "\n", "}", "\n", "}", "\n", "return", "\n", "}", ")", "\n", "}", ")", "\n", "}" ]
// 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
train
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", "(", "Event", "{", "Name", ":", "EventNameWindowCmdWebContentsOpenDevTools", ",", "TargetID", ":", "w", ".", "id", "}", ")", "\n", "}" ]
// OpenDevTools opens the dev tools
[ "OpenDevTools", "opens", "the", "dev", "tools" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/window.go#L420-L425
train
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", ".", "m", ".", "Lock", "(", ")", "\n", "w", ".", "o", ".", "Height", "=", "PtrInt", "(", "height", ")", "\n", "w", ".", "o", ".", "Width", "=", "PtrInt", "(", "width", ")", "\n", "w", ".", "m", ".", "Unlock", "(", ")", "\n", "_", ",", "err", "=", "synchronousEvent", "(", "w", ".", "c", ",", "w", ",", "w", ".", "w", ",", "Event", "{", "Name", ":", "EventNameWindowCmdResize", ",", "TargetID", ":", "w", ".", "id", ",", "WindowOptions", ":", "&", "WindowOptions", "{", "Height", ":", "PtrInt", "(", "height", ")", ",", "Width", ":", "PtrInt", "(", "width", ")", "}", "}", ",", "EventNameWindowEventResize", ")", "\n", "return", "\n", "}" ]
// Resize resizes the window
[ "Resize", "resizes", "the", "window" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/window.go#L428-L438
train
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", ".", "Lock", "(", ")", "\n", "w", ".", "o", ".", "Height", "=", "r", ".", "Height", "\n", "w", ".", "o", ".", "Width", "=", "r", ".", "Width", "\n", "w", ".", "o", ".", "X", "=", "r", ".", "X", "\n", "w", ".", "o", ".", "Y", "=", "r", ".", "Y", "\n", "w", ".", "m", ".", "Unlock", "(", ")", "\n", "_", ",", "err", "=", "synchronousEvent", "(", "w", ".", "c", ",", "w", ",", "w", ".", "w", ",", "Event", "{", "Name", ":", "EventNameWindowCmdSetBounds", ",", "TargetID", ":", "w", ".", "id", ",", "Bounds", ":", "&", "r", "}", ",", "EventNameWindowEventResize", ")", "\n", "return", "\n", "}" ]
// 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
train
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", "(", "w", ".", "c", ",", "w", ",", "w", ".", "w", ",", "Event", "{", "Name", ":", "EventNameWindowCmdRestore", ",", "TargetID", ":", "w", ".", "id", "}", ",", "EventNameWindowEventRestore", ")", "\n", "return", "\n", "}" ]
// Restore restores the window
[ "Restore", "restores", "the", "window" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/window.go#L456-L462
train
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", "{", "return", "\n", "}", "\n", "var", "e", "=", "Event", "{", "Message", ":", "newEventMessage", "(", "message", ")", ",", "Name", ":", "eventNameWindowCmdMessage", ",", "TargetID", ":", "w", ".", "id", "}", "\n", "if", "len", "(", "callbacks", ")", ">", "0", "{", "e", ".", "CallbackID", "=", "w", ".", "callbackIdentifier", ".", "new", "(", ")", "\n", "w", ".", "On", "(", "eventNameWindowEventMessageCallback", ",", "func", "(", "i", "Event", ")", "(", "deleteListener", "bool", ")", "{", "if", "i", ".", "CallbackID", "==", "e", ".", "CallbackID", "{", "for", "_", ",", "c", ":=", "range", "callbacks", "{", "c", "(", "i", ".", "Message", ")", "\n", "}", "\n", "deleteListener", "=", "true", "\n", "}", "\n", "return", "\n", "}", ")", "\n", "}", "\n", "return", "w", ".", "w", ".", "write", "(", "e", ")", "\n", "}" ]
// 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", "in", "JS" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/window.go#L469-L487
train
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", "(", "w", ".", "c", ",", "w", ",", "w", ".", "w", ",", "Event", "{", "Name", ":", "EventNameWindowCmdShow", ",", "TargetID", ":", "w", ".", "id", "}", ",", "EventNameWindowEventShow", ")", "\n", "return", "\n", "}" ]
// Show shows the window
[ "Show", "shows", "the", "window" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/window.go#L490-L496
train
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", "(", "w", ".", "c", ",", "w", ",", "w", ".", "w", ",", "Event", "{", "Name", ":", "EventNameWindowCmdUnmaximize", ",", "TargetID", ":", "w", ".", "id", "}", ",", "EventNameWindowEventUnmaximize", ")", "\n", "return", "\n", "}" ]
// Unmaximize unmaximize the window
[ "Unmaximize", "unmaximize", "the", "window" ]
5d5f1436743467b9a7cd9e9c90dc4ab47b96be90
https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/window.go#L499-L505
train
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", ",", "\"", "\"", ")", "\n\n", "mac", ":=", "hmac", ".", "New", "(", "sha1", ".", "New", ",", "[", "]", "byte", "(", "secret", ")", ")", "\n", "_", ",", "err", ":=", "mac", ".", "Write", "(", "payload", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n", "expectedMAC", ":=", "hex", ".", "EncodeToString", "(", "mac", ".", "Sum", "(", "nil", ")", ")", "\n\n", "if", "!", "hmac", ".", "Equal", "(", "[", "]", "byte", "(", "signature", ")", ",", "[", "]", "byte", "(", "expectedMAC", ")", ")", "{", "return", "expectedMAC", ",", "&", "SignatureError", "{", "signature", "}", "\n", "}", "\n", "return", "expectedMAC", ",", "err", "\n", "}" ]
// 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
train
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", "]", "interface", "{", "}", "\n", "key", ":=", "ha", ".", "Name", "\n\n", "switch", "ha", ".", "Source", "{", "case", "SourceHeader", ":", "source", "=", "headers", "\n", "key", "=", "textproto", ".", "CanonicalMIMEHeaderKey", "(", "ha", ".", "Name", ")", "\n", "case", "SourceQuery", ",", "SourceQueryAlias", ":", "source", "=", "query", "\n", "case", "SourcePayload", ":", "source", "=", "payload", "\n", "case", "SourceString", ":", "return", "ha", ".", "Name", ",", "true", "\n", "case", "SourceEntirePayload", ":", "r", ",", "err", ":=", "json", ".", "Marshal", "(", "payload", ")", "\n\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "false", "\n", "}", "\n\n", "return", "string", "(", "r", ")", ",", "true", "\n", "case", "SourceEntireHeaders", ":", "r", ",", "err", ":=", "json", ".", "Marshal", "(", "headers", ")", "\n\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "false", "\n", "}", "\n\n", "return", "string", "(", "r", ")", ",", "true", "\n", "case", "SourceEntireQuery", ":", "r", ",", "err", ":=", "json", ".", "Marshal", "(", "query", ")", "\n\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "false", "\n", "}", "\n\n", "return", "string", "(", "r", ")", ",", "true", "\n", "}", "\n\n", "if", "source", "!=", "nil", "{", "return", "ExtractParameterAsString", "(", "key", ",", "*", "source", ")", "\n", "}", "\n\n", "return", "\"", "\"", ",", "false", "\n", "}" ]
// 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
train
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", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "*", "h", "=", "append", "(", "*", "h", ",", "Header", "{", "Name", ":", "splitResult", "[", "0", "]", ",", "Value", ":", "splitResult", "[", "1", "]", "}", ")", "\n", "return", "nil", "\n", "}" ]
// 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
train
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
train
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", ",", "0", ")", "\n\n", "for", "i", ":=", "range", "h", ".", "JSONStringParameters", "{", "if", "arg", ",", "ok", ":=", "h", ".", "JSONStringParameters", "[", "i", "]", ".", "Get", "(", "headers", ",", "query", ",", "payload", ")", ";", "ok", "{", "var", "newArg", "map", "[", "string", "]", "interface", "{", "}", "\n\n", "decoder", ":=", "json", ".", "NewDecoder", "(", "strings", ".", "NewReader", "(", "string", "(", "arg", ")", ")", ")", "\n", "decoder", ".", "UseNumber", "(", ")", "\n\n", "err", ":=", "decoder", ".", "Decode", "(", "&", "newArg", ")", "\n\n", "if", "err", "!=", "nil", "{", "errors", "=", "append", "(", "errors", ",", "&", "ParseError", "{", "err", "}", ")", "\n", "continue", "\n", "}", "\n\n", "var", "source", "*", "map", "[", "string", "]", "interface", "{", "}", "\n\n", "switch", "h", ".", "JSONStringParameters", "[", "i", "]", ".", "Source", "{", "case", "SourceHeader", ":", "source", "=", "headers", "\n", "case", "SourcePayload", ":", "source", "=", "payload", "\n", "case", "SourceQuery", ",", "SourceQueryAlias", ":", "source", "=", "query", "\n", "}", "\n\n", "if", "source", "!=", "nil", "{", "key", ":=", "h", ".", "JSONStringParameters", "[", "i", "]", ".", "Name", "\n\n", "if", "h", ".", "JSONStringParameters", "[", "i", "]", ".", "Source", "==", "SourceHeader", "{", "key", "=", "textproto", ".", "CanonicalMIMEHeaderKey", "(", "h", ".", "JSONStringParameters", "[", "i", "]", ".", "Name", ")", "\n", "}", "\n\n", "ReplaceParameter", "(", "key", ",", "source", ",", "newArg", ")", "\n", "}", "else", "{", "errors", "=", "append", "(", "errors", ",", "&", "SourceError", "{", "h", ".", "JSONStringParameters", "[", "i", "]", "}", ")", "\n", "}", "\n", "}", "else", "{", "errors", "=", "append", "(", "errors", ",", "&", "ArgumentError", "{", "h", ".", "JSONStringParameters", "[", "i", "]", "}", ")", "\n", "}", "\n", "}", "\n\n", "if", "len", "(", "errors", ")", ">", "0", "{", "return", "errors", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// 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
train
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", ".", "Errorf", "(", "\"", "\"", ",", "hook", ".", "ID", ")", "\n", "}", "\n\n", "*", "h", "=", "append", "(", "*", "h", ",", "hook", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// 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
train
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", ")", "[", "i", "]", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// 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
train
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", ")", "{", "switch", "{", "case", "r", ".", "And", "!=", "nil", ":", "return", "r", ".", "And", ".", "Evaluate", "(", "headers", ",", "query", ",", "payload", ",", "body", ",", "remoteAddr", ")", "\n", "case", "r", ".", "Or", "!=", "nil", ":", "return", "r", ".", "Or", ".", "Evaluate", "(", "headers", ",", "query", ",", "payload", ",", "body", ",", "remoteAddr", ")", "\n", "case", "r", ".", "Not", "!=", "nil", ":", "return", "r", ".", "Not", ".", "Evaluate", "(", "headers", ",", "query", ",", "payload", ",", "body", ",", "remoteAddr", ")", "\n", "case", "r", ".", "Match", "!=", "nil", ":", "return", "r", ".", "Match", ".", "Evaluate", "(", "headers", ",", "query", ",", "payload", ",", "body", ",", "remoteAddr", ")", "\n", "}", "\n\n", "return", "false", ",", "nil", "\n", "}" ]
// 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
train
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", ")", "{", "res", ":=", "true", "\n\n", "for", "_", ",", "v", ":=", "range", "r", "{", "rv", ",", "err", ":=", "v", ".", "Evaluate", "(", "headers", ",", "query", ",", "payload", ",", "body", ",", "remoteAddr", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "\n\n", "res", "=", "res", "&&", "rv", "\n", "if", "!", "res", "{", "return", "res", ",", "nil", "\n", "}", "\n", "}", "\n\n", "return", "res", ",", "nil", "\n", "}" ]
// 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
train
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", ")", "{", "rv", ",", "err", ":=", "Rules", "(", "r", ")", ".", "Evaluate", "(", "headers", ",", "query", ",", "payload", ",", "body", ",", "remoteAddr", ")", "\n", "return", "!", "rv", ",", "err", "\n", "}" ]
// 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
train
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", ")", "{", "if", "r", ".", "Type", "==", "IPWhitelist", "{", "return", "CheckIPWhitelist", "(", "remoteAddr", ",", "r", ".", "IPRange", ")", "\n", "}", "\n", "if", "r", ".", "Type", "==", "ScalrSignature", "{", "return", "CheckScalrSignature", "(", "*", "headers", ",", "*", "body", ",", "r", ".", "Secret", ",", "true", ")", "\n", "}", "\n\n", "if", "arg", ",", "ok", ":=", "r", ".", "Parameter", ".", "Get", "(", "headers", ",", "query", ",", "payload", ")", ";", "ok", "{", "switch", "r", ".", "Type", "{", "case", "MatchValue", ":", "return", "arg", "==", "r", ".", "Value", ",", "nil", "\n", "case", "MatchRegex", ":", "return", "regexp", ".", "MatchString", "(", "r", ".", "Regex", ",", "arg", ")", "\n", "case", "MatchHashSHA1", ":", "_", ",", "err", ":=", "CheckPayloadSignature", "(", "*", "body", ",", "r", ".", "Secret", ",", "arg", ")", "\n", "return", "err", "==", "nil", ",", "err", "\n", "case", "MatchHashSHA256", ":", "_", ",", "err", ":=", "CheckPayloadSignature256", "(", "*", "body", ",", "r", ".", "Secret", ",", "arg", ")", "\n", "return", "err", "==", "nil", ",", "err", "\n", "}", "\n", "}", "\n", "return", "false", ",", "nil", "\n", "}" ]
// 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
train
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
train
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
train
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", "&", "0xfffff", "\n", "}" ]
// 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
train
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", ".", "BigEndian", ".", "PutUint32", "(", "b", "[", "versTCFL", ":", "]", ",", "vtf", ")", "\n", "}" ]
// 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
train
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
train
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
train
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
train
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", "[", "nextHdr", "]", "=", "i", ".", "NextHeader", "\n", "b", "[", "hopLimit", "]", "=", "i", ".", "HopLimit", "\n", "copy", "(", "b", "[", "v6SrcAddr", ":", "v6SrcAddr", "+", "IPv6AddressSize", "]", ",", "i", ".", "SrcAddr", ")", "\n", "copy", "(", "b", "[", "v6DstAddr", ":", "v6DstAddr", "+", "IPv6AddressSize", "]", ",", "i", ".", "DstAddr", ")", "\n", "}" ]
// 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
train
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", "\\xff", "\"", "\n", "return", "solicitedNodeMulticastPrefix", "+", "addr", "[", "len", "(", "addr", ")", "-", "3", ":", "]", "\n", "}" ]
// 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
train
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", "(", ")", "\n\n", "if", "e", ".", "rcvList", ".", "Empty", "(", ")", "{", "err", ":=", "tcpip", ".", "ErrWouldBlock", "\n", "if", "e", ".", "rcvClosed", "{", "err", "=", "tcpip", ".", "ErrClosedForReceive", "\n", "}", "\n", "e", ".", "rcvMu", ".", "Unlock", "(", ")", "\n", "return", "buffer", ".", "View", "{", "}", ",", "tcpip", ".", "ControlMessages", "{", "}", ",", "err", "\n", "}", "\n\n", "p", ":=", "e", ".", "rcvList", ".", "Front", "(", ")", "\n", "e", ".", "rcvList", ".", "Remove", "(", "p", ")", "\n", "e", ".", "rcvBufSize", "-=", "p", ".", "data", ".", "Size", "(", ")", "\n\n", "e", ".", "rcvMu", ".", "Unlock", "(", ")", "\n\n", "if", "addr", "!=", "nil", "{", "*", "addr", "=", "p", ".", "senderAddress", "\n", "}", "\n\n", "return", "p", ".", "data", ".", "ToView", "(", ")", ",", "tcpip", ".", "ControlMessages", "{", "HasTimestamp", ":", "true", ",", "Timestamp", ":", "p", ".", "timestamp", "}", ",", "nil", "\n", "}" ]
// 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
train
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", "stateConnected", ":", "return", "false", ",", "nil", "\n\n", "case", "stateBound", ":", "if", "to", "==", "nil", "{", "return", "false", ",", "tcpip", ".", "ErrDestinationRequired", "\n", "}", "\n", "return", "false", ",", "nil", "\n", "default", ":", "return", "false", ",", "tcpip", ".", "ErrInvalidEndpointState", "\n", "}", "\n\n", "e", ".", "mu", ".", "RUnlock", "(", ")", "\n", "defer", "e", ".", "mu", ".", "RLock", "(", ")", "\n\n", "e", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "e", ".", "mu", ".", "Unlock", "(", ")", "\n\n", "// 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", "\n", "}", "\n\n", "// The state is still 'initial', so try to bind the endpoint.", "if", "err", ":=", "e", ".", "bindLocked", "(", "tcpip", ".", "FullAddress", "{", "}", ")", ";", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "\n\n", "return", "true", ",", "nil", "\n", "}" ]
// 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", "in", "exclusive", "mode", ".", "Returns", "true", "for", "retry", "if", "preparation", "should", "be", "retried", "." ]
70ebca9c30730cf3887cdef3b85bb96ed7a97593
https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/transport/udp/endpoint.go#L203-L236
train
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", ",", "*", "tcpip", ".", "Error", ")", "{", "netProto", ",", "err", ":=", "e", ".", "checkV4Mapped", "(", "&", "addr", ",", "false", ")", "\n", "if", "err", "!=", "nil", "{", "return", "stack", ".", "Route", "{", "}", ",", "0", ",", "0", ",", "err", "\n", "}", "\n\n", "localAddr", ":=", "e", ".", "id", ".", "LocalAddress", "\n", "if", "header", ".", "IsV4MulticastAddress", "(", "addr", ".", "Addr", ")", "||", "header", ".", "IsV6MulticastAddress", "(", "addr", ".", "Addr", ")", "{", "if", "nicid", "==", "0", "{", "nicid", "=", "e", ".", "multicastNICID", "\n", "}", "\n", "if", "localAddr", "==", "\"", "\"", "{", "localAddr", "=", "e", ".", "multicastAddr", "\n", "}", "\n", "}", "\n\n", "// Find a route to the desired destination.", "r", ",", "err", ":=", "e", ".", "stack", ".", "FindRoute", "(", "nicid", ",", "localAddr", ",", "addr", ".", "Addr", ",", "netProto", ",", "e", ".", "multicastLoop", ")", "\n", "if", "err", "!=", "nil", "{", "return", "stack", ".", "Route", "{", "}", ",", "0", ",", "0", ",", "err", "\n", "}", "\n", "return", "r", ",", "nicid", ",", "netProto", ",", "nil", "\n", "}" ]
// 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
train
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", "{", "}", ",", "nil", "\n", "}" ]
// 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
train
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", ":=", "buffer", ".", "NewPrependable", "(", "header", ".", "UDPMinimumSize", "+", "int", "(", "r", ".", "MaxHeaderLength", "(", ")", ")", ")", "\n\n", "// Initialize the header.", "udp", ":=", "header", ".", "UDP", "(", "hdr", ".", "Prepend", "(", "header", ".", "UDPMinimumSize", ")", ")", "\n\n", "length", ":=", "uint16", "(", "hdr", ".", "UsedLength", "(", ")", "+", "data", ".", "Size", "(", ")", ")", "\n", "udp", ".", "Encode", "(", "&", "header", ".", "UDPFields", "{", "SrcPort", ":", "localPort", ",", "DstPort", ":", "remotePort", ",", "Length", ":", "length", ",", "}", ")", "\n\n", "// Only calculate the checksum if offloading isn't supported.", "if", "r", ".", "Capabilities", "(", ")", "&", "stack", ".", "CapabilityTXChecksumOffload", "==", "0", "{", "xsum", ":=", "r", ".", "PseudoHeaderChecksum", "(", "ProtocolNumber", ",", "length", ")", "\n", "for", "_", ",", "v", ":=", "range", "data", ".", "Views", "(", ")", "{", "xsum", "=", "header", ".", "Checksum", "(", "v", ",", "xsum", ")", "\n", "}", "\n", "udp", ".", "SetChecksum", "(", "^", "udp", ".", "CalculateChecksum", "(", "xsum", ")", ")", "\n", "}", "\n\n", "// Track count of packets sent.", "r", ".", "Stats", "(", ")", ".", "UDP", ".", "PacketsSent", ".", "Increment", "(", ")", "\n\n", "return", "r", ".", "WritePacket", "(", "nil", "/* gso */", ",", "hdr", ",", "data", ",", "ProtocolNumber", ",", "ttl", ")", "\n", "}" ]
// 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
train
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", "(", ")", "\n\n", "return", "tcpip", ".", "FullAddress", "{", "NIC", ":", "e", ".", "regNICID", ",", "Addr", ":", "e", ".", "id", ".", "LocalAddress", ",", "Port", ":", "e", ".", "id", ".", "LocalPort", ",", "}", ",", "nil", "\n", "}" ]
// 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
train
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", "=", "time", ".", "AfterFunc", "(", "time", ".", "Hour", ",", "func", "(", ")", "{", "w", ".", "Assert", "(", ")", "\n", "}", ")", "\n", "t", ".", "timer", ".", "Stop", "(", ")", "\n", "}" ]
// 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
train
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", ".", "state", "==", "timerStateDisabled", "||", "t", ".", "target", ".", "Before", "(", "t", ".", "runtimeTarget", ")", "{", "t", ".", "runtimeTarget", "=", "t", ".", "target", "\n", "t", ".", "timer", ".", "Reset", "(", "d", ")", "\n", "}", "\n\n", "t", ".", "state", "=", "timerStateEnabled", "\n", "}" ]
// 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
train
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", "==", "\"", "\"", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "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", ")", ",", "}", "\n\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "s", ".", "handlers", ")", ";", "i", "++", "{", "ch", ":=", "make", "(", "chan", "header", ",", "8", ")", "\n", "s", ".", "handlers", "[", "i", "]", "=", "ch", "\n", "go", "s", ".", "handler", "(", "ctx", ",", "ch", ")", "\n", "}", "\n\n", "go", "s", ".", "expirer", "(", "ctx", ")", "\n", "go", "s", ".", "reader", "(", "ctx", ")", "\n", "return", "s", ",", "nil", "\n", "}" ]
// 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
train
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", "}", "\n\n", "h", ":=", "header", "(", "v", ")", "\n", "if", "!", "h", ".", "isValid", "(", ")", "||", "h", ".", "op", "(", ")", "!=", "opRequest", "{", "continue", "\n", "}", "\n", "xid", ":=", "h", ".", "xid", "(", ")", "\n\n", "// 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", ")", "]", "\n", "select", "{", "case", "<-", "ctx", ".", "Done", "(", ")", ":", "return", "\n", "case", "ch", "<-", "h", ":", "default", ":", "// drop the packet", "}", "\n", "}", "\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
train
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", ".", "mu", ".", "Lock", "(", ")", "\n", "r", ",", "ok", ":=", "f", ".", "reassemblers", "[", "id", "]", "\n", "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", ")", "\n", "ok", "=", "false", "\n", "}", "\n", "if", "!", "ok", "{", "r", "=", "newReassembler", "(", "id", ")", "\n", "f", ".", "reassemblers", "[", "id", "]", "=", "r", "\n", "f", ".", "rList", ".", "PushFront", "(", "r", ")", "\n", "}", "\n", "f", ".", "mu", ".", "Unlock", "(", ")", "\n\n", "res", ",", "done", ",", "consumed", ":=", "r", ".", "process", "(", "first", ",", "last", ",", "more", ",", "vv", ")", "\n\n", "f", ".", "mu", ".", "Lock", "(", ")", "\n", "f", ".", "size", "+=", "consumed", "\n", "if", "done", "{", "f", ".", "release", "(", "r", ")", "\n", "}", "\n", "// Evict reassemblers if we are consuming more memory than highLimit until", "// we reach lowLimit.", "if", "f", ".", "size", ">", "f", ".", "highLimit", "{", "tail", ":=", "f", ".", "rList", ".", "Back", "(", ")", "\n", "for", "f", ".", "size", ">", "f", ".", "lowLimit", "&&", "tail", "!=", "nil", "{", "f", ".", "release", "(", "tail", ")", "\n", "tail", "=", "tail", ".", "Prev", "(", ")", "\n", "}", "\n", "}", "\n", "f", ".", "mu", ".", "Unlock", "(", ")", "\n", "return", "res", ",", "done", "\n", "}" ]
// 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
train
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", ".", "IsValid", "(", "len", "(", "b", ")", ")", "{", "t", ".", "Error", "(", "\"", "\"", ")", "\n", "}", "\n\n", "for", "_", ",", "f", ":=", "range", "checkers", "{", "f", "(", "t", ",", "[", "]", "header", ".", "Network", "{", "ipv6", "}", ")", "\n", "}", "\n", "if", "t", ".", "Failed", "(", ")", "{", "t", ".", "FailNow", "(", ")", "\n", "}", "\n", "}" ]
// 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
train
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", ":=", "h", "[", "0", "]", ".", "SourceAddress", "(", ")", ";", "a", "!=", "addr", "{", "t", ".", "Errorf", "(", "\"", "\"", ",", "a", ",", "addr", ")", "\n", "}", "\n", "}", "\n", "}" ]
// 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
train
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", ":=", "h", "[", "0", "]", ".", "DestinationAddress", "(", ")", ";", "a", "!=", "addr", "{", "t", ".", "Errorf", "(", "\"", "\"", ",", "a", ",", "addr", ")", "\n", "}", "\n", "}", "\n", "}" ]
// 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
train
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", "(", "h", "[", "0", "]", ".", "Payload", "(", ")", ")", ";", "l", "!=", "plen", "{", "t", ".", "Errorf", "(", "\"", "\"", ",", "l", ",", "plen", ")", "\n", "}", "\n", "}", "\n", "}" ]
// 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
train
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 for now.", "switch", "ip", ":=", "h", "[", "0", "]", ".", "(", "type", ")", "{", "case", "header", ".", "IPv4", ":", "if", "v", ":=", "ip", ".", "FragmentOffset", "(", ")", ";", "v", "!=", "offset", "{", "t", ".", "Errorf", "(", "\"", "\"", ",", "v", ",", "offset", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "}" ]
// 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
train
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 for now.", "switch", "ip", ":=", "h", "[", "0", "]", ".", "(", "type", ")", "{", "case", "header", ".", "IPv4", ":", "if", "v", ":=", "ip", ".", "Flags", "(", ")", ";", "v", "!=", "flags", "{", "t", ".", "Errorf", "(", "\"", "\"", ",", "v", ",", "flags", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "}" ]
// 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
train
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", ",", "l", ":=", "h", "[", "0", "]", ".", "TOS", "(", ")", ";", "v", "!=", "tos", "||", "l", "!=", "label", "{", "t", ".", "Errorf", "(", "\"", "\"", ",", "v", ",", "l", ",", "tos", ",", "label", ")", "\n", "}", "\n", "}", "\n", "}" ]
// 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
train
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", "[", "len", "(", "h", ")", "-", "1", "]", ".", "Payload", "(", ")", ";", "!", "reflect", ".", "DeepEqual", "(", "got", ",", "want", ")", "{", "t", ".", "Errorf", "(", "\"", "\"", ",", "got", ",", "want", ")", "\n", "}", "\n", "}", "\n", "}" ]
// 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", "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", "." ]
70ebca9c30730cf3887cdef3b85bb96ed7a97593
https://github.com/google/netstack/blob/70ebca9c30730cf3887cdef3b85bb96ed7a97593/tcpip/checker/checker.go#L176-L184
train
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", ":=", "h", "[", "0", "]", ".", "TransportProtocol", "(", ")", ";", "p", "!=", "header", ".", "IPv6FragmentHeader", "{", "t", ".", "Errorf", "(", "\"", "\"", ",", "p", ",", "header", ".", "UDPProtocolNumber", ")", "\n", "}", "\n\n", "ipv6Frag", ":=", "header", ".", "IPv6Fragment", "(", "h", "[", "0", "]", ".", "Payload", "(", ")", ")", "\n", "if", "!", "ipv6Frag", ".", "IsValid", "(", ")", "{", "t", ".", "Error", "(", "\"", "\"", ")", "\n", "}", "\n\n", "for", "_", ",", "f", ":=", "range", "checkers", "{", "f", "(", "t", ",", "[", "]", "header", ".", "Network", "{", "h", "[", "0", "]", ",", "ipv6Frag", "}", ")", "\n", "}", "\n", "if", "t", ".", "Failed", "(", ")", "{", "t", ".", "FailNow", "(", ")", "\n", "}", "\n", "}", "\n", "}" ]
// 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
train
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", ":=", "h", "[", "0", "]", "\n", "last", ":=", "h", "[", "len", "(", "h", ")", "-", "1", "]", "\n\n", "if", "p", ":=", "last", ".", "TransportProtocol", "(", ")", ";", "p", "!=", "header", ".", "TCPProtocolNumber", "{", "t", ".", "Errorf", "(", "\"", "\"", ",", "p", ",", "header", ".", "TCPProtocolNumber", ")", "\n", "}", "\n\n", "// Verify the checksum.", "tcp", ":=", "header", ".", "TCP", "(", "last", ".", "Payload", "(", ")", ")", "\n", "l", ":=", "uint16", "(", "len", "(", "tcp", ")", ")", "\n\n", "xsum", ":=", "header", ".", "Checksum", "(", "[", "]", "byte", "(", "first", ".", "SourceAddress", "(", ")", ")", ",", "0", ")", "\n", "xsum", "=", "header", ".", "Checksum", "(", "[", "]", "byte", "(", "first", ".", "DestinationAddress", "(", ")", ")", ",", "xsum", ")", "\n", "xsum", "=", "header", ".", "Checksum", "(", "[", "]", "byte", "{", "0", ",", "byte", "(", "last", ".", "TransportProtocol", "(", ")", ")", "}", ",", "xsum", ")", "\n", "xsum", "=", "header", ".", "Checksum", "(", "[", "]", "byte", "{", "byte", "(", "l", ">>", "8", ")", ",", "byte", "(", "l", ")", "}", ",", "xsum", ")", "\n", "xsum", "=", "header", ".", "Checksum", "(", "tcp", ",", "xsum", ")", "\n\n", "if", "xsum", "!=", "0", "&&", "xsum", "!=", "0xffff", "{", "t", ".", "Errorf", "(", "\"", "\"", ",", "xsum", ",", "tcp", ".", "Checksum", "(", ")", ")", "\n", "}", "\n\n", "// Run the transport checkers.", "for", "_", ",", "f", ":=", "range", "checkers", "{", "f", "(", "t", ",", "tcp", ")", "\n", "}", "\n", "if", "t", ".", "Failed", "(", ")", "{", "t", ".", "FailNow", "(", ")", "\n", "}", "\n", "}", "\n", "}" ]
// 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
train
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", ":=", "h", "[", "len", "(", "h", ")", "-", "1", "]", "\n\n", "if", "p", ":=", "last", ".", "TransportProtocol", "(", ")", ";", "p", "!=", "header", ".", "UDPProtocolNumber", "{", "t", ".", "Errorf", "(", "\"", "\"", ",", "p", ",", "header", ".", "UDPProtocolNumber", ")", "\n", "}", "\n\n", "udp", ":=", "header", ".", "UDP", "(", "last", ".", "Payload", "(", ")", ")", "\n", "for", "_", ",", "f", ":=", "range", "checkers", "{", "f", "(", "t", ",", "udp", ")", "\n", "}", "\n", "if", "t", ".", "Failed", "(", ")", "{", "t", ".", "FailNow", "(", ")", "\n", "}", "\n", "}", "\n", "}" ]
// 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
train
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", ".", "SourcePort", "(", ")", ";", "p", "!=", "port", "{", "t", ".", "Errorf", "(", "\"", "\"", ",", "p", ",", "port", ")", "\n", "}", "\n", "}", "\n", "}" ]
// 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
train
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", "!=", "port", "{", "t", ".", "Errorf", "(", "\"", "\"", ",", "p", ",", "port", ")", "\n", "}", "\n", "}", "\n", "}" ]
// 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
train
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", ".", "(", "header", ".", "TCP", ")", "\n", "if", "!", "ok", "{", "return", "\n", "}", "\n\n", "if", "s", ":=", "tcp", ".", "SequenceNumber", "(", ")", ";", "s", "!=", "seq", "{", "t", ".", "Errorf", "(", "\"", "\"", ",", "s", ",", "seq", ")", "\n", "}", "\n", "}", "\n", "}" ]
// 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
train
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", ".", "(", "header", ".", "TCP", ")", "\n", "if", "!", "ok", "{", "return", "\n", "}", "\n\n", "if", "s", ":=", "tcp", ".", "AckNumber", "(", ")", ";", "s", "!=", "seq", "{", "t", ".", "Errorf", "(", "\"", "\"", ",", "s", ",", "seq", ")", "\n", "}", "\n", "}", "\n", "}" ]
// 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
train
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", "if", "!", "ok", "{", "return", "\n", "}", "\n\n", "if", "w", ":=", "tcp", ".", "WindowSize", "(", ")", ";", "w", "!=", "window", "{", "t", ".", "Errorf", "(", "\"", "\"", ",", "w", ",", "window", ")", "\n", "}", "\n", "}", "\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
train
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", ".", "(", "header", ".", "TCP", ")", "\n", "if", "!", "ok", "{", "return", "\n", "}", "\n\n", "if", "f", ":=", "tcp", ".", "Flags", "(", ")", ";", "f", "!=", "flags", "{", "t", ".", "Errorf", "(", "\"", "\"", ",", "f", ",", "flags", ")", "\n", "}", "\n", "}", "\n", "}" ]
// 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
train
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", ".", "TCP", ")", "\n", "if", "!", "ok", "{", "return", "\n", "}", "\n\n", "if", "f", ":=", "tcp", ".", "Flags", "(", ")", ";", "(", "f", "&", "mask", ")", "!=", "(", "flags", "&", "mask", ")", "{", "t", ".", "Errorf", "(", "\"", "\"", ",", "f", ",", "flags", ",", "mask", ")", "\n", "}", "\n", "}", "\n", "}" ]
// 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
train
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", "(", ")", "\n", "tcp", ",", "ok", ":=", "h", ".", "(", "header", ".", "TCP", ")", "\n", "if", "!", "ok", "{", "return", "\n", "}", "\n", "var", "gotSACKBlocks", "[", "]", "header", ".", "SACKBlock", "\n\n", "opts", ":=", "[", "]", "byte", "(", "tcp", ".", "Options", "(", ")", ")", "\n", "limit", ":=", "len", "(", "opts", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "limit", ";", "{", "switch", "opts", "[", "i", "]", "{", "case", "header", ".", "TCPOptionEOL", ":", "i", "=", "limit", "\n", "case", "header", ".", "TCPOptionNOP", ":", "i", "++", "\n", "case", "header", ".", "TCPOptionSACK", ":", "if", "i", "+", "2", ">", "limit", "{", "// Malformed SACK block.", "t", ".", "Errorf", "(", "\"", "\"", ",", "opts", ")", "\n", "}", "\n", "sackOptionLen", ":=", "int", "(", "opts", "[", "i", "+", "1", "]", ")", "\n", "if", "i", "+", "sackOptionLen", ">", "limit", "||", "(", "sackOptionLen", "-", "2", ")", "%", "8", "!=", "0", "{", "// Malformed SACK block.", "t", ".", "Errorf", "(", "\"", "\"", ",", "opts", ")", "\n", "}", "\n", "numBlocks", ":=", "sackOptionLen", "/", "8", "\n", "for", "j", ":=", "0", ";", "j", "<", "numBlocks", ";", "j", "++", "{", "start", ":=", "binary", ".", "BigEndian", ".", "Uint32", "(", "opts", "[", "i", "+", "2", "+", "j", "*", "8", ":", "]", ")", "\n", "end", ":=", "binary", ".", "BigEndian", ".", "Uint32", "(", "opts", "[", "i", "+", "2", "+", "j", "*", "8", "+", "4", ":", "]", ")", "\n", "gotSACKBlocks", "=", "append", "(", "gotSACKBlocks", ",", "header", ".", "SACKBlock", "{", "Start", ":", "seqnum", ".", "Value", "(", "start", ")", ",", "End", ":", "seqnum", ".", "Value", "(", "end", ")", ",", "}", ")", "\n", "}", "\n", "i", "+=", "sackOptionLen", "\n", "default", ":", "// We don't recognize this option, just skip over it.", "if", "i", "+", "2", ">", "limit", "{", "break", "\n", "}", "\n", "l", ":=", "int", "(", "opts", "[", "i", "+", "1", "]", ")", "\n", "if", "l", "<", "2", "||", "i", "+", "l", ">", "limit", "{", "break", "\n", "}", "\n", "i", "+=", "l", "\n", "}", "\n", "}", "\n\n", "if", "!", "reflect", ".", "DeepEqual", "(", "gotSACKBlocks", ",", "sackBlocks", ")", "{", "t", ".", "Errorf", "(", "\"", "\"", ",", "gotSACKBlocks", ",", "sackBlocks", ")", "\n", "}", "\n", "}", "\n", "}" ]
// 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
train
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", "(", ")", ";", "!", "reflect", ".", "DeepEqual", "(", "got", ",", "want", ")", "{", "t", ".", "Errorf", "(", "\"", "\"", ",", "got", ",", "want", ")", "\n", "}", "\n", "}", "\n", "}" ]
// 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
train
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", ".", "Views", "(", ")", "\n", "size", ":=", "curr", ".", "vv", ".", "Size", "(", ")", "\n\n", "if", "curr", ".", "offset", "!=", "0", "{", "return", "buffer", ".", "VectorisedView", "{", "}", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "curr", ".", "offset", ")", "\n", "}", "\n\n", "for", "h", ".", "Len", "(", ")", ">", "0", "{", "curr", ":=", "heap", ".", "Pop", "(", "h", ")", ".", "(", "fragment", ")", "\n", "if", "int", "(", "curr", ".", "offset", ")", "<", "size", "{", "curr", ".", "vv", ".", "TrimFront", "(", "size", "-", "int", "(", "curr", ".", "offset", ")", ")", "\n", "}", "else", "if", "int", "(", "curr", ".", "offset", ")", ">", "size", "{", "return", "buffer", ".", "VectorisedView", "{", "}", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "size", ",", "curr", ".", "offset", ")", "\n", "}", "\n", "size", "+=", "curr", ".", "vv", ".", "Size", "(", ")", "\n", "views", "=", "append", "(", "views", ",", "curr", ".", "vv", ".", "Views", "(", ")", "...", ")", "\n", "}", "\n", "return", "buffer", ".", "NewVectorisedView", "(", "size", ",", "views", ")", ",", "nil", "\n", "}" ]
// 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
train
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", "(", "headerView", ")", "\n", "if", "!", "h", ".", "IsValid", "(", "vv", ".", "Size", "(", ")", ")", "{", "return", "\n", "}", "\n\n", "vv", ".", "TrimFront", "(", "header", ".", "IPv6MinimumSize", ")", "\n", "vv", ".", "CapLength", "(", "int", "(", "h", ".", "PayloadLength", "(", ")", ")", ")", "\n\n", "p", ":=", "h", ".", "TransportProtocol", "(", ")", "\n", "if", "p", "==", "header", ".", "ICMPv6ProtocolNumber", "{", "e", ".", "handleICMP", "(", "r", ",", "headerView", ",", "vv", ")", "\n", "return", "\n", "}", "\n\n", "r", ".", "Stats", "(", ")", ".", "IP", ".", "PacketsDelivered", ".", "Increment", "(", ")", "\n", "e", ".", "dispatcher", ".", "DeliverTransportPacket", "(", "r", ",", "p", ",", "headerView", ",", "vv", ")", "\n", "}" ]
// 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
train
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", "stack", ".", "LinkEndpoint", ")", "(", "stack", ".", "NetworkEndpoint", ",", "*", "tcpip", ".", "Error", ")", "{", "return", "&", "endpoint", "{", "nicid", ":", "nicid", ",", "id", ":", "stack", ".", "NetworkEndpointID", "{", "LocalAddress", ":", "addr", "}", ",", "linkEP", ":", "linkEP", ",", "linkAddrCache", ":", "linkAddrCache", ",", "dispatcher", ":", "dispatcher", ",", "}", ",", "nil", "\n", "}" ]
// 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
train
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
train