-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
025ce30
commit 3d8b1c2
Showing
8 changed files
with
54 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ package namesys | |
|
||
type Resolver interface { | ||
Resolve(string) (string, error) | ||
Matches(string) bool | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,42 @@ | ||
package namesys | ||
|
||
import ( | ||
"strings" | ||
"errors" | ||
|
||
mdag "github.com/jbenet/go-ipfs/merkledag" | ||
"github.com/jbenet/go-ipfs/routing" | ||
) | ||
|
||
var ErrCouldntResolve = errors.New("could not resolve name.") | ||
|
||
type MasterResolver struct { | ||
dns *DNSResolver | ||
routing *RoutingResolver | ||
pro *ProquintResolver | ||
res []Resolver | ||
} | ||
|
||
func NewMasterResolver(r routing.IpfsRouting, dag *mdag.DAGService) *MasterResolver { | ||
mr := new(MasterResolver) | ||
mr.dns = new(DNSResolver) | ||
mr.pro = new(ProquintResolver) | ||
mr.routing = NewRoutingResolver(r, dag) | ||
mr.res = []Resolver{ | ||
new(DNSResolver), | ||
new(ProquintResolver), | ||
NewRoutingResolver(r, dag), | ||
} | ||
return mr | ||
} | ||
|
||
func (mr *MasterResolver) Resolve(name string) (string, error) { | ||
if strings.Contains(name, ".") { | ||
return mr.dns.Resolve(name) | ||
for _, r := range mr.res { | ||
if r.Matches(name) { | ||
return r.Resolve(name) | ||
} | ||
} | ||
return "", ErrCouldntResolve | ||
} | ||
|
||
if strings.Contains(name, "-") { | ||
return mr.pro.Resolve(name) | ||
func (mr *MasterResolver) Matches(name string) bool { | ||
for _, r := range mr.res { | ||
if r.Matches(name) { | ||
return true | ||
} | ||
} | ||
|
||
return mr.routing.Resolve(name) | ||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters