Provide discovery hint from the outside (ref #192)
This commit is contained in:
parent
e8a9abaf40
commit
dd1197236d
@ -56,6 +56,7 @@ func startGUI(cfg GUIConfiguration, m *Model) error {
|
|||||||
router.Post("/rest/shutdown", restPostShutdown)
|
router.Post("/rest/shutdown", restPostShutdown)
|
||||||
router.Post("/rest/error", restPostError)
|
router.Post("/rest/error", restPostError)
|
||||||
router.Post("/rest/error/clear", restClearErrors)
|
router.Post("/rest/error/clear", restClearErrors)
|
||||||
|
router.Post("/rest/discovery/hint", restPostDiscoveryHint)
|
||||||
|
|
||||||
mr := martini.New()
|
mr := martini.New()
|
||||||
if len(cfg.User) > 0 && len(cfg.Password) > 0 {
|
if len(cfg.User) > 0 && len(cfg.Password) > 0 {
|
||||||
@ -233,6 +234,15 @@ func showGuiError(err string) {
|
|||||||
guiErrorsMut.Unlock()
|
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 {
|
func basic(username string, passhash string) http.HandlerFunc {
|
||||||
return func(res http.ResponseWriter, req *http.Request) {
|
return func(res http.ResponseWriter, req *http.Request) {
|
||||||
error := func() {
|
error := func() {
|
||||||
|
|||||||
@ -90,6 +90,14 @@ func (d *Discoverer) Lookup(node string) []string {
|
|||||||
return nil
|
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 {
|
func (d *Discoverer) announcementPkt() []byte {
|
||||||
var addrs []Address
|
var addrs []Address
|
||||||
for _, astr := range d.listenAddrs {
|
for _, astr := range d.listenAddrs {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user