Add fmt make target, incorporate address length fix from qiwenmin, add a shortcut for saving your keys
This commit is contained in:
4
Makefile
4
Makefile
@@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
USER_GH=eyedeekay
|
USER_GH=eyedeekay
|
||||||
VERSION=0.32.3
|
VERSION=0.32.31
|
||||||
packagename=sam3
|
packagename=sam3
|
||||||
|
|
||||||
echo:
|
echo:
|
||||||
@@ -22,3 +22,5 @@ copier:
|
|||||||
echo '#! /usr/bin/env sh' > deb/copy.sh
|
echo '#! /usr/bin/env sh' > deb/copy.sh
|
||||||
echo 'for f in $$(ls); do scp $$f/*.deb user@192.168.99.106:~/DEBIAN_PKGS/$$f/main/; done' >> deb/copy.sh
|
echo 'for f in $$(ls); do scp $$f/*.deb user@192.168.99.106:~/DEBIAN_PKGS/$$f/main/; done' >> deb/copy.sh
|
||||||
|
|
||||||
|
fmt:
|
||||||
|
find . -name '*.go' -exec gofmt -w -s {} \;
|
||||||
|
@@ -108,6 +108,10 @@ func (s *DatagramSession) ReadFrom(b []byte) (n int, addr net.Addr, err error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *DatagramSession) Accept() (net.Conn, error) {
|
||||||
|
return s, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (s *DatagramSession) Read(b []byte) (n int, err error) {
|
func (s *DatagramSession) Read(b []byte) (n int, err error) {
|
||||||
rint, _, rerr := s.ReadFrom(b)
|
rint, _, rerr := s.ReadFrom(b)
|
||||||
return rint, rerr
|
return rint, rerr
|
||||||
@@ -147,6 +151,10 @@ func (s *DatagramSession) LocalAddr() net.Addr {
|
|||||||
return s.LocalI2PAddr()
|
return s.LocalI2PAddr()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *DatagramSession) Addr() net.Addr {
|
||||||
|
return s.LocalI2PAddr()
|
||||||
|
}
|
||||||
|
|
||||||
func (s *DatagramSession) Lookup(name string) (a net.Addr, err error) {
|
func (s *DatagramSession) Lookup(name string) (a net.Addr, err error) {
|
||||||
var sam *SAM
|
var sam *SAM
|
||||||
sam, err = NewSAM(s.samAddr)
|
sam, err = NewSAM(s.samAddr)
|
||||||
|
@@ -22,7 +22,7 @@ func SetType(s string) func(*SAMEmit) error {
|
|||||||
c.Style = s
|
c.Style = s
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return fmt.Errorf("Invalid session STYLE=%s, must be STREAM, DATAGRAM, or RAW")
|
return fmt.Errorf("Invalid session STYLE=%s, must be STREAM, DATAGRAM, or RAW", s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
2
emit.go
2
emit.go
@@ -76,7 +76,7 @@ func (e *SAMEmit) ConnectBytes(dest string) []byte {
|
|||||||
|
|
||||||
func (e *SAMEmit) Accept() string {
|
func (e *SAMEmit) Accept() string {
|
||||||
return fmt.Sprintf(
|
return fmt.Sprintf(
|
||||||
"STREAM ACCEPT ID=%s",
|
"STREAM ACCEPT ID=%s %s %s",
|
||||||
e.I2PConfig.ID(),
|
e.I2PConfig.ID(),
|
||||||
e.I2PConfig.FromPort(),
|
e.I2PConfig.FromPort(),
|
||||||
e.I2PConfig.ToPort(),
|
e.I2PConfig.ToPort(),
|
||||||
|
@@ -7,6 +7,7 @@ import (
|
|||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -31,6 +32,18 @@ func NewKeys(addr I2PAddr, both string) I2PKeys {
|
|||||||
return I2PKeys{addr, both}
|
return I2PKeys{addr, both}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// fileExists checks if a file exists and is not a directory before we
|
||||||
|
// try using it to prevent further errors.
|
||||||
|
func fileExists(filename string) (bool, error) {
|
||||||
|
info, err := os.Stat(filename)
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
return false, nil
|
||||||
|
} else if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
return !info.IsDir(), nil
|
||||||
|
}
|
||||||
|
|
||||||
// load keys from non standard format
|
// load keys from non standard format
|
||||||
func LoadKeysIncompat(r io.Reader) (k I2PKeys, err error) {
|
func LoadKeysIncompat(r io.Reader) (k I2PKeys, err error) {
|
||||||
var buff bytes.Buffer
|
var buff bytes.Buffer
|
||||||
@@ -42,12 +55,40 @@ func LoadKeysIncompat(r io.Reader) (k I2PKeys, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// load keys from non-standard format by specifying a text file.
|
||||||
|
// If the file does not exist, generate keys, otherwise, fail
|
||||||
|
// closed.
|
||||||
|
func LoadKeys(r string) (I2PKeys, error) {
|
||||||
|
exists, err := fileExists(r)
|
||||||
|
if err != nil {
|
||||||
|
return I2PKeys{}, err
|
||||||
|
}
|
||||||
|
if exists {
|
||||||
|
fi, err := os.Open(r)
|
||||||
|
if err != nil {
|
||||||
|
return I2PKeys{}, err
|
||||||
|
}
|
||||||
|
defer fi.Close()
|
||||||
|
return LoadKeysIncompat(fi)
|
||||||
|
}
|
||||||
|
return I2PKeys{}, err
|
||||||
|
}
|
||||||
|
|
||||||
// store keys in non standard format
|
// store keys in non standard format
|
||||||
func StoreKeysIncompat(k I2PKeys, w io.Writer) (err error) {
|
func StoreKeysIncompat(k I2PKeys, w io.Writer) (err error) {
|
||||||
_, err = io.WriteString(w, k.Address.Base64()+"\n"+k.Both)
|
_, err = io.WriteString(w, k.Address.Base64()+"\n"+k.Both)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func StoreKeys(k I2PKeys, r string) error {
|
||||||
|
fi, err := os.Open(r)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer fi.Close()
|
||||||
|
return StoreKeysIncompat(k, fi)
|
||||||
|
}
|
||||||
|
|
||||||
// Returns the public keys of the I2PKeys.
|
// Returns the public keys of the I2PKeys.
|
||||||
func (k I2PKeys) Addr() I2PAddr {
|
func (k I2PKeys) Addr() I2PAddr {
|
||||||
return k.Address
|
return k.Address
|
||||||
|
@@ -150,7 +150,7 @@ func Test_StreamingServerClient(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ExampleStreamSession() {
|
func ExampleStreamSession() {
|
||||||
// Creates a new StreamingSession, dials to zzz.i2p and gets a SAMConn
|
// Creates a new StreamingSession, dials to idk.i2p and gets a SAMConn
|
||||||
// which behaves just like a normal net.Conn.
|
// which behaves just like a normal net.Conn.
|
||||||
|
|
||||||
const samBridge = "127.0.0.1:7656"
|
const samBridge = "127.0.0.1:7656"
|
||||||
@@ -172,7 +172,7 @@ func ExampleStreamSession() {
|
|||||||
fmt.Println(err.Error())
|
fmt.Println(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
someone, err := sam.Lookup("zzz.i2p")
|
someone, err := sam.Lookup("idk.i2p")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
fmt.Println(err.Error())
|
||||||
return
|
return
|
||||||
@@ -192,17 +192,17 @@ func ExampleStreamSession() {
|
|||||||
buf := make([]byte, 4096)
|
buf := make([]byte, 4096)
|
||||||
n, err := conn.Read(buf)
|
n, err := conn.Read(buf)
|
||||||
if !strings.Contains(strings.ToLower(string(buf[:n])), "http") && !strings.Contains(strings.ToLower(string(buf[:n])), "html") {
|
if !strings.Contains(strings.ToLower(string(buf[:n])), "http") && !strings.Contains(strings.ToLower(string(buf[:n])), "html") {
|
||||||
fmt.Printf("Probably failed to StreamSession.DialI2P(zzz.i2p)? It replied %d bytes, but nothing that looked like http/html", n)
|
fmt.Printf("Probably failed to StreamSession.DialI2P(idk.i2p)? It replied %d bytes, but nothing that looked like http/html", n)
|
||||||
log.Printf("Probably failed to StreamSession.DialI2P(zzz.i2p)? It replied %d bytes, but nothing that looked like http/html", n)
|
log.Printf("Probably failed to StreamSession.DialI2P(idk.i2p)? It replied %d bytes, but nothing that looked like http/html", n)
|
||||||
} else {
|
} else {
|
||||||
fmt.Println("Read HTTP/HTML from zzz.i2p")
|
fmt.Println("Read HTTP/HTML from idk.i2p")
|
||||||
log.Println("Read HTTP/HTML from zzz.i2p")
|
log.Println("Read HTTP/HTML from idk.i2p")
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
//Sending HTTP GET /
|
//Sending HTTP GET /
|
||||||
//Read HTTP/HTML from zzz.i2p
|
//Read HTTP/HTML from idk.i2p
|
||||||
}
|
}
|
||||||
|
|
||||||
func ExampleStreamListener() {
|
func ExampleStreamListener() {
|
||||||
|
Reference in New Issue
Block a user