Add Config.{Force,PreferNo}Encryption
This commit is contained in:
parent
69f4c5a7e9
commit
9126db177b
17
client.go
17
client.go
@ -582,7 +582,8 @@ func (cl *Client) establishOutgoingConn(t *Torrent, addr string) (c *connection,
|
|||||||
if nc == nil {
|
if nc == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c, err = cl.handshakesConnection(nc, t, !cl.config.DisableEncryption, utp)
|
encryptFirst := !cl.config.DisableEncryption && !cl.config.PreferNoEncryption
|
||||||
|
c, err = cl.handshakesConnection(nc, t, encryptFirst, utp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
nc.Close()
|
nc.Close()
|
||||||
return
|
return
|
||||||
@ -590,12 +591,12 @@ func (cl *Client) establishOutgoingConn(t *Torrent, addr string) (c *connection,
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
nc.Close()
|
nc.Close()
|
||||||
if cl.config.DisableEncryption {
|
if cl.config.DisableEncryption || cl.config.ForceEncryption {
|
||||||
// We already tried without encryption.
|
// There's no alternate encryption case to try.
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Try again without encryption, using whichever protocol type worked last
|
// Try again with encryption if we didn't earlier, or without if we did,
|
||||||
// time.
|
// using whichever protocol type worked last time.
|
||||||
if utp {
|
if utp {
|
||||||
nc, err = cl.dialUTP(addr, t)
|
nc, err = cl.dialUTP(addr, t)
|
||||||
} else {
|
} else {
|
||||||
@ -605,7 +606,7 @@ func (cl *Client) establishOutgoingConn(t *Torrent, addr string) (c *connection,
|
|||||||
err = fmt.Errorf("error dialing for unencrypted connection: %s", err)
|
err = fmt.Errorf("error dialing for unencrypted connection: %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c, err = cl.handshakesConnection(nc, t, false, utp)
|
c, err = cl.handshakesConnection(nc, t, !encryptFirst, utp)
|
||||||
if err != nil || c == nil {
|
if err != nil || c == nil {
|
||||||
nc.Close()
|
nc.Close()
|
||||||
}
|
}
|
||||||
@ -852,6 +853,10 @@ func (cl *Client) receiveHandshakes(c *connection) (t *Torrent, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if cl.config.ForceEncryption && !c.encrypted {
|
||||||
|
err = errors.New("connection not encrypted")
|
||||||
|
return
|
||||||
|
}
|
||||||
ih, ok, err := cl.connBTHandshake(c, nil)
|
ih, ok, err := cl.connBTHandshake(c, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = fmt.Errorf("error during bt handshake: %s", err)
|
err = fmt.Errorf("error during bt handshake: %s", err)
|
||||||
|
@ -36,8 +36,11 @@ type Config struct {
|
|||||||
// Called to instantiate storage for each added torrent. Builtin backends
|
// Called to instantiate storage for each added torrent. Builtin backends
|
||||||
// are in the storage package. If not set, the "file" implementation is
|
// are in the storage package. If not set, the "file" implementation is
|
||||||
// used.
|
// used.
|
||||||
DefaultStorage storage.ClientImpl
|
DefaultStorage storage.ClientImpl
|
||||||
DisableEncryption bool `long:"disable-encryption"`
|
|
||||||
|
DisableEncryption bool `long:"disable-encryption"`
|
||||||
|
ForceEncryption bool // Don't allow unobfuscated connections.
|
||||||
|
PreferNoEncryption bool
|
||||||
|
|
||||||
IPBlocklist iplist.Ranger
|
IPBlocklist iplist.Ranger
|
||||||
DisableIPv6 bool `long:"disable-ipv6"`
|
DisableIPv6 bool `long:"disable-ipv6"`
|
||||||
|
Loading…
x
Reference in New Issue
Block a user