repurpose the useless cmd application nobody used into a place to put the i2pkeys library outside of both the SAM libraries
This commit is contained in:
@@ -19,3 +19,15 @@ func Test_Basic(t *testing.T) {
|
|||||||
}
|
}
|
||||||
fmt.Println(keys.String())
|
fmt.Println(keys.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Test_Basic_Lookup(t *testing.T) {
|
||||||
|
fmt.Println("Test_Basic")
|
||||||
|
fmt.Println("\tAttaching to SAM at " + yoursam)
|
||||||
|
keys, err := Lookup("idk.i2p")
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err.Error())
|
||||||
|
t.Fail()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fmt.Println(keys.String())
|
||||||
|
}
|
||||||
|
53
Lookup.go
53
Lookup.go
@@ -1,14 +1,47 @@
|
|||||||
package i2pkeys
|
package i2pkeys
|
||||||
|
|
||||||
import "net"
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
type SimpleLookup struct {
|
func Lookup(addr string) (*I2PAddr, error) {
|
||||||
}
|
conn, err := net.Dial("tcp", "127.0.0.1:7656")
|
||||||
|
if err != nil {
|
||||||
func Lookup(i2paddr string) net.Addr {
|
return nil, err
|
||||||
return nil
|
}
|
||||||
}
|
defer conn.Close()
|
||||||
|
_, err = conn.Write([]byte("HELLO VERSION MIN=3.1 MAX=3.1\n"))
|
||||||
func LookupI2P(i2paddr string) *I2PAddr {
|
if err != nil {
|
||||||
return nil
|
return nil, err
|
||||||
|
}
|
||||||
|
buf := make([]byte, 4096)
|
||||||
|
n, err := conn.Read(buf)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if n < 1 {
|
||||||
|
return nil, fmt.Errorf("no data received")
|
||||||
|
}
|
||||||
|
if strings.Contains(string(buf[:n]), "RESULT=OK") {
|
||||||
|
_, err = conn.Write([]byte(fmt.Sprintf("NAMING LOOKUP NAME=%s\n", addr)))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
n, err = conn.Read(buf)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if n < 1 {
|
||||||
|
return nil, fmt.Errorf("no destination data received")
|
||||||
|
}
|
||||||
|
value := strings.Split(string(buf[:n]), "VALUE=")[1]
|
||||||
|
addr, err := NewI2PAddrFromString(value)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &addr, err
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("no result received")
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user