mirror of
https://github.com/go-i2p/goSam.git
synced 2025-06-10 17:44:59 -04:00
38 lines
641 B
Go
38 lines
641 B
Go
package goSam
|
|
|
|
import (
|
|
"fmt"
|
|
"math"
|
|
"math/rand"
|
|
)
|
|
|
|
func (c *Client) createStreamSession(dest string) (id int32, newDest string, err error) {
|
|
if dest == "" {
|
|
dest = "TRANSIENT"
|
|
}
|
|
|
|
var r *Reply
|
|
|
|
id = rand.Int31n(math.MaxInt32)
|
|
createCmd := fmt.Sprintf("SESSION CREATE STYLE=STREAM ID=%d DESTINATION=%s", id, dest)
|
|
r, err = c.sendCmd(createCmd)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
if r.Topic != "SESSION" || r.Type != "STATUS" {
|
|
err = fmt.Errorf("Unknown Reply: %+v\n", r)
|
|
return
|
|
}
|
|
|
|
result := r.Pairs["RESULT"]
|
|
if result != "OK" {
|
|
err = ReplyError{ResultKeyNotFound, r}
|
|
return
|
|
}
|
|
|
|
newDest = r.Pairs["DESTINATION"]
|
|
|
|
return
|
|
}
|