From 48db835e94169da3167a2867ea05c5e7f5c7c755 Mon Sep 17 00:00:00 2001 From: Age Date: Thu, 22 Dec 2016 00:11:18 +1100 Subject: [PATCH] swarm/api: correct bzz.resolve functionality --- swarm/api/ens.go | 45 +++++++++++++++++++++++++++++++++++++++++++++ swarm/swarm.go | 9 ++++++++- 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 swarm/api/ens.go diff --git a/swarm/api/ens.go b/swarm/api/ens.go new file mode 100644 index 0000000000..26abe72e2f --- /dev/null +++ b/swarm/api/ens.go @@ -0,0 +1,45 @@ +// Copyright 2016 The go-ethereum Authors +// This file is part of the go-ethereum library. +// +// The go-ethereum library is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// The go-ethereum library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with the go-ethereum library. If not, see . + + +package api + +import ( + "github.com/ethereum/go-ethereum/logger/glog" + "github.com/ethereum/go-ethereum/logger" +) + +// Implements an RPC service +type Ens struct { + api *Api +} + +func NewEns(api *Api) *Ens { + return &Ens{api} +} + +// Resolves ENS domains to contentHashes. +// Could use swarm Api.Resolve if we wanted bzz.resolve both domains and hashes. +func (self *Ens) Resolve(domain string) (string, error) { + contentHash, err := self.api.dns.Resolve(domain) + if err != nil { + err = ErrResolve(err) + glog.V(logger.Warn).Infof("DNS error : %v", err) + } + glog.V(logger.Detail).Infof("host lookup: %v -> %v", err) + return contentHash.Hex(), err + +} diff --git a/swarm/swarm.go b/swarm/swarm.go index 7e38944de0..02c93e2ce2 100644 --- a/swarm/swarm.go +++ b/swarm/swarm.go @@ -233,12 +233,19 @@ func (self *Swarm) APIs() []rpc.API { Service: &Info{self.config, chequebook.ContractParams}, Public: true, }, + { + Namespace: "bzz", + Version: "0.1", + Service: api.NewEns(self.api), + Public: true, + }, // admin APIs { Namespace: "bzz", Version: "0.1", Service: api.NewFileSystem(self.api), - Public: false}, + Public: false, + }, { Namespace: "bzz", Version: "0.1",