human-readable hash experiment
This commit is contained in:
9897
etc/samcatd/hashwords.txt
Normal file
9897
etc/samcatd/hashwords.txt
Normal file
File diff suppressed because it is too large
Load Diff
9903
hashhash/default.go
Normal file
9903
hashhash/default.go
Normal file
File diff suppressed because it is too large
Load Diff
76
hashhash/hashhash.go
Normal file
76
hashhash/hashhash.go
Normal file
@ -0,0 +1,76 @@
|
||||
package hashhash
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
)
|
||||
|
||||
import (
|
||||
"github.com/boreq/friendlyhash"
|
||||
)
|
||||
|
||||
type Hasher struct {
|
||||
FileName string
|
||||
split []string
|
||||
length int
|
||||
hasher *friendlyhash.FriendlyHash
|
||||
}
|
||||
|
||||
func (h *Hasher) dictionary() []string {
|
||||
if len(h.split) > 0 {
|
||||
return h.split
|
||||
}
|
||||
bytes, _ := ioutil.ReadFile(h.FileName)
|
||||
h.split = strings.Split(string(bytes), "\n")
|
||||
return h.split
|
||||
}
|
||||
|
||||
func (h *Hasher) Friendly(input string) (string, error) {
|
||||
slice, err := h.hasher.Humanize([]byte(input))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return strings.Join(slice, "."), nil
|
||||
}
|
||||
|
||||
func (h *Hasher) Unfriendly(input string) (string, error) {
|
||||
slice := strings.Split(input, ".")
|
||||
hash, err := h.hasher.Dehumanize(slice)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return string(hash), nil
|
||||
}
|
||||
|
||||
func (h *Hasher) Unfriendlyslice(input []string) (string, error) {
|
||||
hash, err := h.hasher.Dehumanize(input)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return string(hash), nil
|
||||
}
|
||||
|
||||
func NewHasher(length int) (*Hasher, error) {
|
||||
var h Hasher
|
||||
var err error
|
||||
h.FileName = ""
|
||||
h.length = length
|
||||
h.split = Default()
|
||||
h.hasher, err = friendlyhash.New(h.dictionary(), length)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &h, nil
|
||||
}
|
||||
|
||||
func Init(FileName string, length int) (*Hasher, error) {
|
||||
var h Hasher
|
||||
var err error
|
||||
h.FileName = FileName
|
||||
h.length = length
|
||||
h.hasher, err = friendlyhash.New(h.dictionary(), length)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &h, nil
|
||||
}
|
@ -6,10 +6,12 @@ import (
|
||||
"net"
|
||||
//"os"
|
||||
//"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
import (
|
||||
"github.com/eyedeekay/sam-forwarder/hashhash"
|
||||
"github.com/eyedeekay/sam-forwarder/i2pkeys"
|
||||
"github.com/eyedeekay/sam-forwarder/interface"
|
||||
"github.com/eyedeekay/sam3"
|
||||
@ -28,6 +30,7 @@ type SAMClientForwarder struct {
|
||||
|
||||
samConn *sam3.SAM
|
||||
SamKeys i2pkeys.I2PKeys
|
||||
Hasher *hashhash.Hasher
|
||||
connectStream *sam3.StreamSession
|
||||
dest string
|
||||
addr i2pkeys.I2PAddr
|
||||
@ -211,6 +214,13 @@ func (f *SAMClientForwarder) Base32() string {
|
||||
return f.SamKeys.Addr().Base32()
|
||||
}
|
||||
|
||||
//Base32Readable returns the base32 address where the local service is being forwarded
|
||||
func (f *SAMClientForwarder) Base32Readable() string {
|
||||
b32 := strings.Replace(f.Base32(), ".b32.i2p", "", 1)
|
||||
rhash, _ := f.Hasher.Friendly(b32)
|
||||
return rhash + " " + strconv.Itoa(len(b32))
|
||||
}
|
||||
|
||||
//Base64 returns the base64 address of the local destiantion
|
||||
func (f *SAMClientForwarder) Base64() string {
|
||||
return f.SamKeys.Addr().Base64()
|
||||
@ -251,6 +261,7 @@ func (f *SAMClientForwarder) Serve() error {
|
||||
return err
|
||||
}
|
||||
log.Println("Forwarding client to i2p address:", f.addr.Base32())
|
||||
log.Println("Human-readable hash of Client:\n ", f.Base32Readable())
|
||||
go f.forward(conn)
|
||||
}
|
||||
}
|
||||
@ -290,6 +301,10 @@ func (s *SAMClientForwarder) Load() (samtunnel.SAMTunnel, error) {
|
||||
}
|
||||
log.Println("Saved tunnel keys for", s.TunName)
|
||||
}
|
||||
s.Hasher, err = hashhash.NewHasher(len(strings.Replace(s.Base32(), ".b32.i2p", "", 1)))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
s.up = true
|
||||
return s, nil
|
||||
}
|
||||
|
@ -9,10 +9,12 @@ import (
|
||||
"net/http/httputil"
|
||||
//"os"
|
||||
//"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
import (
|
||||
"github.com/eyedeekay/sam-forwarder/hashhash"
|
||||
"github.com/eyedeekay/sam-forwarder/i2pkeys"
|
||||
"github.com/eyedeekay/sam-forwarder/interface"
|
||||
"github.com/eyedeekay/sam3"
|
||||
@ -31,6 +33,7 @@ type SAMForwarder struct {
|
||||
|
||||
samConn *sam3.SAM
|
||||
SamKeys i2pkeys.I2PKeys
|
||||
Hasher *hashhash.Hasher
|
||||
publishStream *sam3.StreamSession
|
||||
publishListen *sam3.StreamListener
|
||||
|
||||
@ -334,6 +337,13 @@ func (f *SAMForwarder) Base32() string {
|
||||
return f.SamKeys.Addr().Base32()
|
||||
}
|
||||
|
||||
//Base32Readable returns the base32 address where the local service is being forwarded
|
||||
func (f *SAMForwarder) Base32Readable() string {
|
||||
b32 := strings.Replace(f.Base32(), ".b32.i2p", "", 1)
|
||||
rhash, _ := f.Hasher.Friendly(b32)
|
||||
return rhash + " " + strconv.Itoa(len(b32))
|
||||
}
|
||||
|
||||
//Base64 returns the base64 address where the local service is being forwarded
|
||||
func (f *SAMForwarder) Base64() string {
|
||||
return f.SamKeys.Addr().Base64()
|
||||
@ -352,8 +362,8 @@ func (f *SAMForwarder) Serve() error {
|
||||
return err
|
||||
}
|
||||
log.Println("Starting Listener.")
|
||||
b := string(f.SamKeys.Addr().Base32())
|
||||
log.Println("SAM Listener created,", b)
|
||||
log.Println("SAM Listener created,", f.Base32())
|
||||
log.Println("Human-readable hash:\n ", f.Base32Readable())
|
||||
|
||||
for {
|
||||
conn, err := f.publishListen.AcceptI2P()
|
||||
@ -402,6 +412,10 @@ func (s *SAMForwarder) Load() (samtunnel.SAMTunnel, error) {
|
||||
}
|
||||
log.Println("Saved tunnel keys for", s.TunName)
|
||||
}
|
||||
s.Hasher, err = hashhash.NewHasher(len(strings.Replace(s.Base32(), ".b32.i2p", "", 1)))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
s.up = true
|
||||
return s, nil
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ import (
|
||||
)
|
||||
|
||||
import (
|
||||
"github.com/eyedeekay/sam-forwarder/hashhash"
|
||||
"github.com/eyedeekay/sam-forwarder/i2pkeys"
|
||||
"github.com/eyedeekay/sam-forwarder/interface"
|
||||
"github.com/eyedeekay/sam3"
|
||||
@ -31,6 +32,7 @@ type SAMSSUClientForwarder struct {
|
||||
|
||||
samConn *sam3.SAM
|
||||
SamKeys i2pkeys.I2PKeys
|
||||
Hasher *hashhash.Hasher
|
||||
connectStream *sam3.DatagramSession
|
||||
dest string
|
||||
addr i2pkeys.I2PAddr
|
||||
@ -218,6 +220,13 @@ func (f *SAMSSUClientForwarder) Base32() string {
|
||||
return f.SamKeys.Addr().Base32()
|
||||
}
|
||||
|
||||
//Base32Readable returns the base32 address where the local service is being forwarded
|
||||
func (f *SAMSSUClientForwarder) Base32Readable() string {
|
||||
b32 := strings.Replace(f.Base32(), ".b32.i2p", "", 1)
|
||||
rhash, _ := f.Hasher.Friendly(b32)
|
||||
return rhash + " " + strconv.Itoa(len(b32))
|
||||
}
|
||||
|
||||
//Base64 returns the base64 address of the local destination
|
||||
func (f *SAMSSUClientForwarder) Base64() string {
|
||||
return f.SamKeys.Addr().Base64()
|
||||
@ -282,7 +291,7 @@ func (f *SAMSSUClientForwarder) Serve() error {
|
||||
}
|
||||
log.Println("SAM datagram session established.")
|
||||
log.Printf("Connected to localhost %v\n", f.publishConnection)
|
||||
|
||||
log.Println("Human-readable hash of Client:\n ", f.Base32Readable())
|
||||
/* Close := false
|
||||
for !Close {
|
||||
//addr, err := net.ResolveUDPAddr("udp", f.Target())
|
||||
@ -318,6 +327,10 @@ func (s *SAMSSUClientForwarder) Load() (samtunnel.SAMTunnel, error) {
|
||||
}
|
||||
log.Println("Saved tunnel keys for", s.TunName)
|
||||
}
|
||||
s.Hasher, err = hashhash.NewHasher(len(strings.Replace(s.Base32(), ".b32.i2p", "", 1)))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
s.up = true
|
||||
return s, nil
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ import (
|
||||
)
|
||||
|
||||
import (
|
||||
"github.com/eyedeekay/sam-forwarder/hashhash"
|
||||
"github.com/eyedeekay/sam-forwarder/i2pkeys"
|
||||
"github.com/eyedeekay/sam-forwarder/interface"
|
||||
"github.com/eyedeekay/sam3"
|
||||
@ -31,6 +32,7 @@ type SAMSSUForwarder struct {
|
||||
|
||||
samConn *sam3.SAM
|
||||
SamKeys i2pkeys.I2PKeys
|
||||
Hasher *hashhash.Hasher
|
||||
publishConnection *sam3.DatagramSession
|
||||
clientConnection net.PacketConn
|
||||
|
||||
@ -247,6 +249,13 @@ func (f *SAMSSUForwarder) Base32() string {
|
||||
return f.SamKeys.Addr().Base32()
|
||||
}
|
||||
|
||||
//Base32Readable returns the base32 address where the local service is being forwarded
|
||||
func (f *SAMSSUForwarder) Base32Readable() string {
|
||||
b32 := strings.Replace(f.Base32(), ".b32.i2p", "", 1)
|
||||
rhash, _ := f.Hasher.Friendly(b32)
|
||||
return rhash + " " + strconv.Itoa(len(b32))
|
||||
}
|
||||
|
||||
//Base64 returns the base64 address where the local service is being forwarded
|
||||
func (f *SAMSSUForwarder) Base64() string {
|
||||
return f.SamKeys.Addr().Base64()
|
||||
@ -280,9 +289,8 @@ func (f *SAMSSUForwarder) Serve() error {
|
||||
|
||||
log.Println("SAM datagram session established.")
|
||||
log.Println("Starting Forwarder.")
|
||||
b := string(f.SamKeys.Addr().Base32())
|
||||
log.Println("SAM Keys loaded,", b)
|
||||
|
||||
log.Println("SAM Keys loaded,", f.Base32())
|
||||
log.Println("Human-readable hash:\n ", f.Base32Readable())
|
||||
for {
|
||||
f.forward()
|
||||
}
|
||||
@ -307,6 +315,10 @@ func (s *SAMSSUForwarder) Load() (samtunnel.SAMTunnel, error) {
|
||||
}
|
||||
log.Println("Saved tunnel keys for", s.TunName)
|
||||
}
|
||||
s.Hasher, err = hashhash.NewHasher(len(strings.Replace(s.Base32(), ".b32.i2p", "", 1)))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
s.up = true
|
||||
return s, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user