server: simplify host creation
This commit is contained in:
parent
ab9133c917
commit
a6f507710b
|
@ -127,6 +127,9 @@ func (s *Server) onionPath(name string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
|
r.Header.Set("X-Forwarded-For", r.RemoteAddr)
|
||||||
|
r.Header.Set("X-Request-Ingress", time.Now().String())
|
||||||
|
|
||||||
if r.RequestURI == rpc.DefaultRPCPath {
|
if r.RequestURI == rpc.DefaultRPCPath {
|
||||||
s.rpcS.ServeHTTP(w, r)
|
s.rpcS.ServeHTTP(w, r)
|
||||||
return
|
return
|
||||||
|
@ -184,9 +187,10 @@ func (rs *RPCServer) AddHost(req routerpc.AddHostRequest, resp *routerpc.AddHost
|
||||||
token := uuid.New()
|
token := uuid.New()
|
||||||
|
|
||||||
var pKey *rsa.PrivateKey
|
var pKey *rsa.PrivateKey
|
||||||
|
|
||||||
if kk, ok := req.PrivKey.(*rsa.PrivateKey); ok {
|
if kk, ok := req.PrivKey.(*rsa.PrivateKey); ok {
|
||||||
pKey = kk
|
pKey = kk
|
||||||
|
} else {
|
||||||
|
return errors.New("there must be a 1024 bit RSA private key")
|
||||||
}
|
}
|
||||||
|
|
||||||
oi, err := rs.tor.AddOnion(pKey, 80, "127.0.0.1:"+rs.cfg.WebPort)
|
oi, err := rs.tor.AddOnion(pKey, 80, "127.0.0.1:"+rs.cfg.WebPort)
|
||||||
|
@ -196,6 +200,7 @@ func (rs *RPCServer) AddHost(req routerpc.AddHostRequest, resp *routerpc.AddHost
|
||||||
|
|
||||||
resp.OnionHostname = oi.OnionID + ".onion"
|
resp.OnionHostname = oi.OnionID + ".onion"
|
||||||
resp.Token = token
|
resp.Token = token
|
||||||
|
resp.PrivKey = pKey
|
||||||
|
|
||||||
if req.Hostname != "" {
|
if req.Hostname != "" {
|
||||||
rs.Server.ts.AddHost(req.Hostname, token)
|
rs.Server.ts.AddHost(req.Hostname, token)
|
||||||
|
|
|
@ -76,5 +76,5 @@ func (t *Tor) AddOnion(pKey *rsa.PrivateKey, virtPort uint16, destination string
|
||||||
VirtPort: virtPort,
|
VirtPort: virtPort,
|
||||||
Target: destination,
|
Target: destination,
|
||||||
},
|
},
|
||||||
}, pKey, false)
|
}, pKey, true)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue