diff options
author | kali kaneko (leap communications) <kali@leap.se> | 2021-11-29 01:46:27 +0100 |
---|---|---|
committer | kali kaneko (leap communications) <kali@leap.se> | 2021-11-29 18:14:16 +0100 |
commit | 18f52af5be3a9a0c73811706108f790d65ee9c67 (patch) | |
tree | e13cbacb47d56919caa9c44a2b45dec1497a7860 /vendor/github.com/cretz/bine/control/cmd_misc.go | |
parent | ebcef0d57b6ecb5a40c6579f6be07182dd3033ba (diff) |
[pkg] update vendor
Diffstat (limited to 'vendor/github.com/cretz/bine/control/cmd_misc.go')
-rw-r--r-- | vendor/github.com/cretz/bine/control/cmd_misc.go | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/vendor/github.com/cretz/bine/control/cmd_misc.go b/vendor/github.com/cretz/bine/control/cmd_misc.go new file mode 100644 index 0000000..6c3fa49 --- /dev/null +++ b/vendor/github.com/cretz/bine/control/cmd_misc.go @@ -0,0 +1,92 @@ +package control + +import ( + "strings" + + "github.com/cretz/bine/torutil" +) + +// Signal invokes SIGNAL. +func (c *Conn) Signal(signal string) error { + return c.sendRequestIgnoreResponse("SIGNAL %v", signal) +} + +// Quit invokes QUIT. +func (c *Conn) Quit() error { + return c.sendRequestIgnoreResponse("QUIT") +} + +// MapAddresses invokes MAPADDRESS and returns mapped addresses. +func (c *Conn) MapAddresses(addresses ...*KeyVal) ([]*KeyVal, error) { + cmd := "MAPADDRESS" + for _, address := range addresses { + cmd += " " + address.Key + "=" + address.Val + } + resp, err := c.SendRequest(cmd) + if err != nil { + return nil, err + } + data := resp.DataWithReply() + ret := make([]*KeyVal, 0, len(data)) + for _, address := range data { + mappedAddress := &KeyVal{} + mappedAddress.Key, mappedAddress.Val, _ = torutil.PartitionString(address, '=') + ret = append(ret, mappedAddress) + } + return ret, nil +} + +// GetInfo invokes GETINTO and returns values for requested keys. +func (c *Conn) GetInfo(keys ...string) ([]*KeyVal, error) { + resp, err := c.SendRequest("GETINFO %v", strings.Join(keys, " ")) + if err != nil { + return nil, err + } + ret := make([]*KeyVal, 0, len(resp.Data)) + for _, val := range resp.Data { + infoVal := &KeyVal{} + infoVal.Key, infoVal.Val, _ = torutil.PartitionString(val, '=') + if infoVal.Val, err = torutil.UnescapeSimpleQuotedStringIfNeeded(infoVal.Val); err != nil { + return nil, err + } + ret = append(ret, infoVal) + } + return ret, nil +} + +// PostDescriptor invokes POSTDESCRIPTOR. +func (c *Conn) PostDescriptor(descriptor string, purpose string, cache string) error { + cmd := "+POSTDESCRIPTOR" + if purpose != "" { + cmd += " purpose=" + purpose + } + if cache != "" { + cmd += " cache=" + cache + } + cmd += "\r\n" + descriptor + "\r\n." + return c.sendRequestIgnoreResponse(cmd) +} + +// UseFeatures invokes USEFEATURE. +func (c *Conn) UseFeatures(features ...string) error { + return c.sendRequestIgnoreResponse("USEFEATURE " + strings.Join(features, " ")) +} + +// ResolveAsync invokes RESOLVE. +func (c *Conn) ResolveAsync(address string, reverse bool) error { + cmd := "RESOLVE " + if reverse { + cmd += "mode=reverse " + } + return c.sendRequestIgnoreResponse(cmd + address) +} + +// TakeOwnership invokes TAKEOWNERSHIP. +func (c *Conn) TakeOwnership() error { + return c.sendRequestIgnoreResponse("TAKEOWNERSHIP") +} + +// DropGuards invokes DROPGUARDS. +func (c *Conn) DropGuards() error { + return c.sendRequestIgnoreResponse("DROPGUARDS") +} |