Skip to content

Commit

Permalink
Provide discovery hint from the outside (ref #192)
Browse files Browse the repository at this point in the history
  • Loading branch information
calmh committed May 13, 2014
1 parent e8a9aba commit dd11972
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
10 changes: 10 additions & 0 deletions cmd/syncthing/gui.go
Expand Up @@ -56,6 +56,7 @@ func startGUI(cfg GUIConfiguration, m *Model) error {
router.Post("/rest/shutdown", restPostShutdown)
router.Post("/rest/error", restPostError)
router.Post("/rest/error/clear", restClearErrors)
router.Post("/rest/discovery/hint", restPostDiscoveryHint)

mr := martini.New()
if len(cfg.User) > 0 && len(cfg.Password) > 0 {
Expand Down Expand Up @@ -233,6 +234,15 @@ func showGuiError(err string) {
guiErrorsMut.Unlock()
}

func restPostDiscoveryHint(r *http.Request) {
var qs = r.URL.Query()
var node = qs.Get("node")
var addr = qs.Get("addr")
if len(node) != 0 && len(addr) != 0 && discoverer != nil {
discoverer.Hint(node, []string{addr})
}
}

func basic(username string, passhash string) http.HandlerFunc {
return func(res http.ResponseWriter, req *http.Request) {
error := func() {
Expand Down
8 changes: 8 additions & 0 deletions discover/discover.go
Expand Up @@ -90,6 +90,14 @@ func (d *Discoverer) Lookup(node string) []string {
return nil
}

func (d *Discoverer) Hint(node string, addrs []string) {
resAddrs := resolveAddrs(addrs)
d.registerNode(nil, Node{
ID: node,
Addresses: resAddrs,
})
}

func (d *Discoverer) announcementPkt() []byte {
var addrs []Address
for _, astr := range d.listenAddrs {
Expand Down

0 comments on commit dd11972

Please sign in to comment.