naming.go 795 B

1234567891011121314151617181920212223242526272829303132333435
  1. package goSam
  2. import (
  3. "fmt"
  4. "os"
  5. )
  6. // Lookup askes SAM for the internal i2p address from name
  7. func (c *Client) Lookup(name string) (string, error) {
  8. r, err := c.sendCmd("NAMING LOOKUP NAME=%s\n", name)
  9. if err != nil {
  10. return "", nil
  11. }
  12. // TODO: move check into sendCmd()
  13. if r.Topic != "NAMING" || r.Type != "REPLY" {
  14. return "", fmt.Errorf("Unknown Reply: %+v\n", r)
  15. }
  16. result := r.Pairs["RESULT"]
  17. if result != "OK" {
  18. return "", ReplyError{result, r}
  19. }
  20. if r.Pairs["NAME"] != name {
  21. // somehow different on i2pd
  22. if r.Pairs["NAME"] != "ME" {
  23. return "", fmt.Errorf("Lookup() Replyed to another name.\nWanted:%s\nGot: %+v\n", name, r)
  24. }
  25. fmt.Fprintln(os.Stderr, "WARNING: Lookup() Replyed to another name. assuming i2pd c++ fluke")
  26. }
  27. return r.Pairs["VALUE"], nil
  28. }