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) {
|
||||
r.Header.Set("X-Forwarded-For", r.RemoteAddr)
|
||||
r.Header.Set("X-Request-Ingress", time.Now().String())
|
||||
|
||||
if r.RequestURI == rpc.DefaultRPCPath {
|
||||
s.rpcS.ServeHTTP(w, r)
|
||||
return
|
||||
|
@ -184,9 +187,10 @@ func (rs *RPCServer) AddHost(req routerpc.AddHostRequest, resp *routerpc.AddHost
|
|||
token := uuid.New()
|
||||
|
||||
var pKey *rsa.PrivateKey
|
||||
|
||||
if kk, ok := req.PrivKey.(*rsa.PrivateKey); ok {
|
||||
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)
|
||||
|
@ -196,6 +200,7 @@ func (rs *RPCServer) AddHost(req routerpc.AddHostRequest, resp *routerpc.AddHost
|
|||
|
||||
resp.OnionHostname = oi.OnionID + ".onion"
|
||||
resp.Token = token
|
||||
resp.PrivKey = pKey
|
||||
|
||||
if req.Hostname != "" {
|
||||
rs.Server.ts.AddHost(req.Hostname, token)
|
||||
|
|
|
@ -76,5 +76,5 @@ func (t *Tor) AddOnion(pKey *rsa.PrivateKey, virtPort uint16, destination string
|
|||
VirtPort: virtPort,
|
||||
Target: destination,
|
||||
},
|
||||
}, pKey, false)
|
||||
}, pKey, true)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue