diff options
author | obscuren <geffobscura@gmail.com> | 2014-08-13 16:52:50 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-08-13 16:52:50 +0800 |
commit | fa881220aedb638f9ee35337b2ca1817c2a8482f (patch) | |
tree | 302f533cdefa3f59ac0ae9f5030d5af91bd76c4d /ethpub/pub.go | |
parent | a760ce05b948e89bc564af20599dcf95698ac0eb (diff) | |
download | go-tangerine-fa881220aedb638f9ee35337b2ca1817c2a8482f.tar go-tangerine-fa881220aedb638f9ee35337b2ca1817c2a8482f.tar.gz go-tangerine-fa881220aedb638f9ee35337b2ca1817c2a8482f.tar.bz2 go-tangerine-fa881220aedb638f9ee35337b2ca1817c2a8482f.tar.lz go-tangerine-fa881220aedb638f9ee35337b2ca1817c2a8482f.tar.xz go-tangerine-fa881220aedb638f9ee35337b2ca1817c2a8482f.tar.zst go-tangerine-fa881220aedb638f9ee35337b2ca1817c2a8482f.zip |
Updated lookup method to include CNAME's as well as A records
Diffstat (limited to 'ethpub/pub.go')
-rw-r--r-- | ethpub/pub.go | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/ethpub/pub.go b/ethpub/pub.go index ab2aae599..762c9a60f 100644 --- a/ethpub/pub.go +++ b/ethpub/pub.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/json" "math/big" + "strconv" "strings" "sync/atomic" @@ -74,8 +75,22 @@ func (self *PEthereum) LookupDomain(domain string) string { if len(domain) > 32 { domain = string(ethcrypto.Sha3Bin([]byte(domain))) } + data := world.Config().Get("DnsReg").StorageString(domain).Bytes() + + // Left padded = A record, Right padded = CNAME + if data[0] == 0 { + data = bytes.TrimLeft(data, "\x00") + var ipSlice []string + for _, d := range data { + ipSlice = append(ipSlice, strconv.Itoa(int(d))) + } + + return strings.Join(ipSlice, ".") + } else { + data = bytes.TrimRight(data, "\x00") - return strings.Trim(world.Config().Get("DnsReg").StorageString(domain).Str(), "\x00") + return string(data) + } } func (lib *PEthereum) GetBlock(hexHash string) *PBlock { |