Esempio n. 1
0
func FromEndpoint(e *e3x.Endpoint, key string) DHT {
	mod := e.Module(moduleKey(key))
	if mod == nil {
		return nil
	}
	return mod.(*dht)
}
Esempio n. 2
0
func FromEndpoint(e *e3x.Endpoint) Bridge {
	mod := e.Module(moduleKey)
	if mod == nil {
		return nil
	}
	return mod.(*module)
}
Esempio n. 3
0
func (mod *module) onNetChange(e *e3x.Endpoint, up, down []net.Addr) error {
	if len(up) == 0 {
		return nil
	}

	for _, x := range e.GetExchanges() {
		go mod.negotiatePaths(x)
	}

	return nil
}
Esempio n. 4
0
func (a *peerAddr) Dial(e *e3x.Endpoint, x *e3x.Exchange) (net.Conn, error) {
	mod, _ := FromEndpoint(e).(*module)
	if mod == nil {
		return nil, net.UnknownNetworkError("unable to bridge")
	}

	router := e.GetExchange(a.router)
	if router == nil {
		return nil, net.UnknownNetworkError("unable to bridge")
	}

	conn := newConnection(x.RemoteHashname(), a, router, func() {
		mod.unregisterConnection(router, x.LocalToken())
	})

	mod.registerConnection(router, x.LocalToken(), conn)

	return conn, nil
}
Esempio n. 5
0
// WellKnown returns an http.Handler which will serve the /.well-known/mesh.json
// document for Endpoint.
func WellKnown(e *e3x.Endpoint) http.Handler {
	return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
		if req.Method != "GET" {
			http.NotFound(rw, req)
			return
		}
		if req.URL.Path != "/.well-known/mesh.json" {
			http.NotFound(rw, req)
			return
		}

		ident, err := e.LocalIdentity()
		if err != nil {
			http.NotFound(rw, req)
			return
		}

		rw.Header().Set("Content-Type", "application/json; charset=utf-8")
		rw.WriteHeader(200)
		json.NewEncoder(rw).Encode(ident)
	})
}
Esempio n. 6
0
func Register(e *e3x.Endpoint, key string) {
	e.Use(moduleKey(key), newDHT(e))
}
Esempio n. 7
0
func Register(e *e3x.Endpoint, key string, conf *chord.Config) {
	e.Use(moduleKey(key), &ring{e, conf, nil})
}
Esempio n. 8
0
func newTransport(e *e3x.Endpoint, m mesh.Mesh) *transport {
	t := &transport{
		e:            e,
		m:            m,
		addressTable: map[hashname.H]*e3x.Addr{},
		localVnodes:  map[string]localRPC{},
	}

	if addr, _ := e.LocalAddr(); addr != nil {
		t.registerAddr(addr)
	}

	e.AddHandler("chord.list", e3x.HandlerFunc(t.handleListVnodes))
	e.AddHandler("chord.ping", e3x.HandlerFunc(t.handlePing))
	e.AddHandler("chord.predecessor.get", e3x.HandlerFunc(t.handleGetPredecessor))
	e.AddHandler("chord.notify", e3x.HandlerFunc(t.handleNotify))
	e.AddHandler("chord.successors.find", e3x.HandlerFunc(t.handleFindSuccessors))
	e.AddHandler("chord.predecessor.clear", e3x.HandlerFunc(t.handleClearPredecessor))
	e.AddHandler("chord.successor.skip", e3x.HandlerFunc(t.handleSkipSuccessor))

	return t
}