Added blocking mode for AddOnion and thus for Listener
This commit is contained in:
parent
3cc4ebc379
commit
d4c87a61f2
33
cmd_onion.go
33
cmd_onion.go
|
@ -39,16 +39,18 @@ type OnionPortSpec struct {
|
|||
|
||||
// NewOnionConfig is a configuration for NewOnion command.
|
||||
type NewOnionConfig struct {
|
||||
PortSpecs []OnionPortSpec
|
||||
PrivateKey crypto.PrivateKey
|
||||
DiscardPK bool
|
||||
Detach bool
|
||||
BasicAuth bool
|
||||
NonAnonymous bool
|
||||
PortSpecs []OnionPortSpec
|
||||
PrivateKey crypto.PrivateKey
|
||||
DiscardPK bool
|
||||
Detach bool
|
||||
BasicAuth bool
|
||||
NonAnonymous bool
|
||||
AwaitForUpload bool
|
||||
}
|
||||
|
||||
// NewOnion issues an ADD_ONION command using configuration config and
|
||||
// returns the parsed response.
|
||||
// NewOnion will block until first descriptor upload if config.AwaitForUpload is set.
|
||||
func (c *Conn) NewOnion(config *NewOnionConfig) (*OnionInfo, error) {
|
||||
const keyTypeRSA = "RSA1024"
|
||||
var err error
|
||||
|
@ -164,6 +166,25 @@ func (c *Conn) NewOnion(config *NewOnionConfig) (*OnionInfo, error) {
|
|||
oi.OnionID = serviceID
|
||||
oi.PrivateKey = hsPrivateKey
|
||||
|
||||
if config.AwaitForUpload {
|
||||
// Wait for service descriptor upload
|
||||
c.StartAsyncReader()
|
||||
if _, err := c.Request("SETEVENTS HS_DESC"); err != nil {
|
||||
return nil, fmt.Errorf("SETEVENTS HS_DESC has failed: %v", err)
|
||||
}
|
||||
eventPrefix := fmt.Sprintf("HS_DESC UPLOADED %s", oi.OnionID)
|
||||
|
||||
for {
|
||||
ev, err := c.NextEvent()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("NextEvent has failed: %v", err)
|
||||
}
|
||||
if strings.HasPrefix(ev.Reply, eventPrefix) {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return oi, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -55,6 +55,7 @@ func (l *onionListener) Addr() net.Addr {
|
|||
// All of virtual ports specified in vports will be mapped to the port to which
|
||||
// the underlying TCP listener binded. PortSpecs in config will be ignored since
|
||||
// there is only one mapping for a vports set is possible.
|
||||
// NewListener will block until first descriptor upload if config.AwaitForUpload is set.
|
||||
func (c *Conn) NewListener(config *NewOnionConfig, vports ...uint16) (net.Listener, error) {
|
||||
var cfg NewOnionConfig
|
||||
if config == nil {
|
||||
|
@ -96,7 +97,6 @@ func (c *Conn) NewListener(config *NewOnionConfig, vports ...uint16) (net.Listen
|
|||
tcpListener.Close()
|
||||
return nil, err
|
||||
}
|
||||
|
||||
oa := &onionAddr{info: oi, port: vports[0]}
|
||||
ol := &onionListener{addr: oa, ctrlConn: c, listener: tcpListener}
|
||||
|
||||
|
|
Reference in New Issue