mirror of
https://github.com/go-i2p/goSam.git
synced 2025-06-10 17:44:59 -04:00

* replyParser had a bug where, when a base64 address ended with '==', the key-value pairs would break. I worked around the issue by switching '==' it with a non-base64 character before the split, and back after. * switch to strings.SplitN and apply gofmt, add test * I don't know exactly why, but checking that the kvPair in replyParser.go is not nil fixes the crash on image-heavy sites. * added new configuration options for host, port, address, and debugging * Fix commit history * added tunnel length control features * added tunnel length control defaults * added length variance feature * added tunnel quantity option * added backup tunnel quantity option * added leaseset configuration options * gofmt * add new options to session establishment commands & gofmt * Reference the change to the debug global in the httpTest.go example * Switch to less than or equal to 16 tunnels at a time. * add in the comments I forgot to do. * add in the comments I forgot to do. * Improved formatting with linter. * Improved formatting with linter. * Ditch interfaces in the functional arguments, instead use different functions for the string and int-based variations. * Fixed broken option * added in missing formatting directive. * change addr to host in client so names are consistent. * change TestClientLookupInvalid back.
39 lines
792 B
Go
39 lines
792 B
Go
package goSam
|
|
|
|
import (
|
|
"fmt"
|
|
"math"
|
|
"math/rand"
|
|
"time"
|
|
)
|
|
|
|
func init() {
|
|
rand.Seed(time.Now().UnixNano())
|
|
}
|
|
|
|
// CreateStreamSession creates a new STREAM Session.
|
|
// Returns the Id for the new Client.
|
|
func (c *Client) CreateStreamSession(dest string) (int32, string, error) {
|
|
if dest == "" {
|
|
dest = "TRANSIENT"
|
|
}
|
|
|
|
id := rand.Int31n(math.MaxInt32)
|
|
r, err := c.sendCmd("SESSION CREATE STYLE=STREAM ID=%d DESTINATION=%s %s\n", id, dest, c.allOptions())
|
|
if err != nil {
|
|
return -1, "", err
|
|
}
|
|
|
|
// TODO: move check into sendCmd()
|
|
if r.Topic != "SESSION" || r.Type != "STATUS" {
|
|
return -1, "", fmt.Errorf("Unknown Reply: %+v\n", r)
|
|
}
|
|
|
|
result := r.Pairs["RESULT"]
|
|
if result != "OK" {
|
|
return -1, "", ReplyError{ResultKeyNotFound, r}
|
|
}
|
|
|
|
return id, r.Pairs["DESTINATION"], nil
|
|
}
|