use Sprintf instead of concatenation for command
This commit is contained in:
@ -2,12 +2,13 @@ package sam3
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/sirupsen/logrus"
|
||||
"math/rand"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/go-i2p/i2pkeys"
|
||||
)
|
||||
|
||||
@ -264,6 +265,7 @@ func (f *I2PConfig) DoZero() string {
|
||||
log.WithField("zeroHopSettings", r).Debug("Zero hop settings applied")
|
||||
return r
|
||||
}
|
||||
|
||||
func (f *I2PConfig) Print() []string {
|
||||
lsk, lspk, lspsk := f.Leasesetsettings()
|
||||
return []string{
|
||||
|
@ -2,9 +2,10 @@ package sam3
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/sirupsen/logrus"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// Option is a SAMEmit Option
|
||||
|
3
emit.go
3
emit.go
@ -2,9 +2,10 @@ package sam3
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/sirupsen/logrus"
|
||||
"net"
|
||||
"strings"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type SAMEmit struct {
|
||||
|
4
log.go
4
log.go
@ -4,9 +4,7 @@ import (
|
||||
logger "github.com/go-i2p/logger"
|
||||
)
|
||||
|
||||
var (
|
||||
log *logger.Logger
|
||||
)
|
||||
var log *logger.Logger
|
||||
|
||||
func InitializeSAM3Logger() {
|
||||
logger.InitializeGoI2PLogger()
|
||||
|
@ -3,13 +3,14 @@ package sam3
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/sirupsen/logrus"
|
||||
"math/rand"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/go-i2p/i2pkeys"
|
||||
)
|
||||
|
||||
|
@ -299,8 +299,7 @@ func ExamplePrimaryStreamListener() {
|
||||
// Got response: Hello world!
|
||||
}
|
||||
|
||||
type exitHandler struct {
|
||||
}
|
||||
type exitHandler struct{}
|
||||
|
||||
func (e *exitHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
w.Write([]byte("Hello world!"))
|
||||
|
3
raw.go
3
raw.go
@ -3,11 +3,12 @@ package sam3
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
"net"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/go-i2p/i2pkeys"
|
||||
)
|
||||
|
||||
|
5
sam3.go
5
sam3.go
@ -6,13 +6,14 @@ import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/sirupsen/logrus"
|
||||
"io"
|
||||
"math/rand"
|
||||
"net"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/go-i2p/i2pkeys"
|
||||
|
||||
. "github.com/go-i2p/i2pkeys"
|
||||
@ -147,7 +148,7 @@ func (sam *SAM) EnsureKeyfile(fname string) (keys i2pkeys.I2PKeys, err error) {
|
||||
sam.Config.I2PConfig.DestinationKeys = keys
|
||||
// save keys
|
||||
var f io.WriteCloser
|
||||
f, err = os.OpenFile(fname, os.O_WRONLY|os.O_CREATE, 0600)
|
||||
f, err = os.OpenFile(fname, os.O_WRONLY|os.O_CREATE, 0o600)
|
||||
if err == nil {
|
||||
err = i2pkeys.StoreKeysIncompat(keys, f)
|
||||
f.Close()
|
||||
|
11
stream.go
11
stream.go
@ -5,12 +5,14 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/go-i2p/i2pkeys"
|
||||
)
|
||||
|
||||
@ -243,7 +245,12 @@ func (s *StreamSession) DialI2P(addr i2pkeys.I2PAddr) (*SAMConn, error) {
|
||||
return nil, err
|
||||
}
|
||||
conn := sam.conn
|
||||
_, err = conn.Write([]byte("STREAM CONNECT ID=" + s.id + " FROM_PORT=" + s.from + " TO_PORT=" + s.to + " DESTINATION=" + addr.Base64() + " SILENT=false\n"))
|
||||
cmd := fmt.Sprintf("STREAM CONNECT ID=%s DESTINATION=%s FROM_PORT=%s TO_PORT=%s SILENT=false\n",
|
||||
s.id,
|
||||
addr.Base64(),
|
||||
s.from,
|
||||
s.to)
|
||||
_, err = conn.Write([]byte(cmd))
|
||||
if err != nil {
|
||||
log.WithError(err).Error("Failed to write STREAM CONNECT command")
|
||||
conn.Close()
|
||||
|
@ -3,12 +3,13 @@ package sam3
|
||||
import (
|
||||
"bufio"
|
||||
"errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
"io"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/go-i2p/i2pkeys"
|
||||
)
|
||||
|
||||
|
@ -1,63 +1,78 @@
|
||||
package sam3
|
||||
|
||||
import (
|
||||
"github.com/sirupsen/logrus"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// Examples and suggestions for options when creating sessions.
|
||||
var (
|
||||
// Suitable options if you are shuffling A LOT of traffic. If unused, this
|
||||
// will waste your resources.
|
||||
Options_Humongous = []string{"inbound.length=3", "outbound.length=3",
|
||||
Options_Humongous = []string{
|
||||
"inbound.length=3", "outbound.length=3",
|
||||
"inbound.lengthVariance=1", "outbound.lengthVariance=1",
|
||||
"inbound.backupQuantity=3", "outbound.backupQuantity=3",
|
||||
"inbound.quantity=6", "outbound.quantity=6"}
|
||||
"inbound.quantity=6", "outbound.quantity=6",
|
||||
}
|
||||
|
||||
// Suitable for shuffling a lot of traffic.
|
||||
Options_Large = []string{"inbound.length=3", "outbound.length=3",
|
||||
Options_Large = []string{
|
||||
"inbound.length=3", "outbound.length=3",
|
||||
"inbound.lengthVariance=1", "outbound.lengthVariance=1",
|
||||
"inbound.backupQuantity=1", "outbound.backupQuantity=1",
|
||||
"inbound.quantity=4", "outbound.quantity=4"}
|
||||
"inbound.quantity=4", "outbound.quantity=4",
|
||||
}
|
||||
|
||||
// Suitable for shuffling a lot of traffic quickly with minimum
|
||||
// anonymity. Uses 1 hop and multiple tunnels.
|
||||
Options_Wide = []string{"inbound.length=1", "outbound.length=1",
|
||||
Options_Wide = []string{
|
||||
"inbound.length=1", "outbound.length=1",
|
||||
"inbound.lengthVariance=1", "outbound.lengthVariance=1",
|
||||
"inbound.backupQuantity=2", "outbound.backupQuantity=2",
|
||||
"inbound.quantity=3", "outbound.quantity=3"}
|
||||
"inbound.quantity=3", "outbound.quantity=3",
|
||||
}
|
||||
|
||||
// Suitable for shuffling medium amounts of traffic.
|
||||
Options_Medium = []string{"inbound.length=3", "outbound.length=3",
|
||||
Options_Medium = []string{
|
||||
"inbound.length=3", "outbound.length=3",
|
||||
"inbound.lengthVariance=1", "outbound.lengthVariance=1",
|
||||
"inbound.backupQuantity=0", "outbound.backupQuantity=0",
|
||||
"inbound.quantity=2", "outbound.quantity=2"}
|
||||
"inbound.quantity=2", "outbound.quantity=2",
|
||||
}
|
||||
|
||||
// Sensible defaults for most people
|
||||
Options_Default = []string{"inbound.length=3", "outbound.length=3",
|
||||
Options_Default = []string{
|
||||
"inbound.length=3", "outbound.length=3",
|
||||
"inbound.lengthVariance=0", "outbound.lengthVariance=0",
|
||||
"inbound.backupQuantity=1", "outbound.backupQuantity=1",
|
||||
"inbound.quantity=1", "outbound.quantity=1"}
|
||||
"inbound.quantity=1", "outbound.quantity=1",
|
||||
}
|
||||
|
||||
// Suitable only for small dataflows, and very short lasting connections:
|
||||
// You only have one tunnel in each direction, so if any of the nodes
|
||||
// through which any of your two tunnels pass through go offline, there will
|
||||
// be a complete halt in the dataflow, until a new tunnel is built.
|
||||
Options_Small = []string{"inbound.length=3", "outbound.length=3",
|
||||
Options_Small = []string{
|
||||
"inbound.length=3", "outbound.length=3",
|
||||
"inbound.lengthVariance=1", "outbound.lengthVariance=1",
|
||||
"inbound.backupQuantity=0", "outbound.backupQuantity=0",
|
||||
"inbound.quantity=1", "outbound.quantity=1"}
|
||||
"inbound.quantity=1", "outbound.quantity=1",
|
||||
}
|
||||
|
||||
// Does not use any anonymization, you connect directly to others tunnel
|
||||
// endpoints, thus revealing your identity but not theirs. Use this only
|
||||
// if you don't care.
|
||||
Options_Warning_ZeroHop = []string{"inbound.length=0", "outbound.length=0",
|
||||
Options_Warning_ZeroHop = []string{
|
||||
"inbound.length=0", "outbound.length=0",
|
||||
"inbound.lengthVariance=0", "outbound.lengthVariance=0",
|
||||
"inbound.backupQuantity=0", "outbound.backupQuantity=0",
|
||||
"inbound.quantity=2", "outbound.quantity=2"}
|
||||
"inbound.quantity=2", "outbound.quantity=2",
|
||||
}
|
||||
)
|
||||
|
||||
func PrimarySessionString() string {
|
||||
@ -115,8 +130,10 @@ func getEnv(key, fallback string) string {
|
||||
return value
|
||||
}
|
||||
|
||||
var SAM_HOST = getEnv("sam_host", "127.0.0.1")
|
||||
var SAM_PORT = getEnv("sam_port", "7656")
|
||||
var (
|
||||
SAM_HOST = getEnv("sam_host", "127.0.0.1")
|
||||
SAM_PORT = getEnv("sam_port", "7656")
|
||||
)
|
||||
|
||||
func SAMDefaultAddr(fallforward string) string {
|
||||
if fallforward == "" {
|
||||
|
Reference in New Issue
Block a user