-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathnaming.go
More file actions
34 lines (28 loc) · 795 Bytes
/
Copy pathnaming.go
File metadata and controls
34 lines (28 loc) · 795 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package goSam
import (
"fmt"
"os"
)
// Lookup askes SAM for the internal i2p address from name
func (c *Client) Lookup(name string) (string, error) {
r, err := c.sendCmd("NAMING LOOKUP NAME=%s\n", name)
if err != nil {
return "", nil
}
// TODO: move check into sendCmd()
if r.Topic != "NAMING" || r.Type != "REPLY" {
return "", fmt.Errorf("Unknown Reply: %+v\n", r)
}
result := r.Pairs["RESULT"]
if result != "OK" {
return "", ReplyError{result, r}
}
if r.Pairs["NAME"] != name {
// somehow different on i2pd
if r.Pairs["NAME"] != "ME" {
return "", fmt.Errorf("Lookup() Replyed to another name.\nWanted:%s\nGot: %+v\n", name, r)
}
fmt.Fprintln(os.Stderr, "WARNING: Lookup() Replyed to another name. assuming i2pd c++ fluke")
}
return r.Pairs["VALUE"], nil
}