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())
|
||||
}
|
||||
|
||||
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())
|
||||
}
|
||||
|
49
Lookup.go
49
Lookup.go
@ -1,14 +1,47 @@
|
||||
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 {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func Lookup(i2paddr string) net.Addr {
|
||||
return nil
|
||||
defer conn.Close()
|
||||
_, err = conn.Write([]byte("HELLO VERSION MIN=3.1 MAX=3.1\n"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func LookupI2P(i2paddr string) *I2PAddr {
|
||||
return nil
|
||||
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