refactor: Connections don't need to know about overlay crypto
This commit is contained in:
1 parent
519aef86fa
commit
006262ed8f
4 files changed
+11
-20
No files matched your search
+1
-14
@@ -196,7 +196,7 @@ func (conn *LocalConnection) run(actionChan <-chan ConnectionAction, finished ch
|
|||||||
RemoteAddr: conn.TCPConn.RemoteAddr().(*net.TCPAddr),
|
RemoteAddr: conn.TCPConn.RemoteAddr().(*net.TCPAddr),
|
||||||
Outbound: conn.outbound,
|
Outbound: conn.outbound,
|
||||||
ConnUID: conn.uid,
|
ConnUID: conn.uid,
|
||||||
Crypto: conn.forwarderCrypto(),
|
SessionKey: conn.SessionKey,
|
||||||
SendControlMessage: conn.sendOverlayControlMessage,
|
SendControlMessage: conn.sendOverlayControlMessage,
|
||||||
Features: intro.Features,
|
Features: intro.Features,
|
||||||
}
|
}
|
||||||
@@ -390,19 +390,6 @@ func (conn *LocalConnection) shutdown(err error) {
|
|||||||
conn.Router.ConnectionMaker.ConnectionTerminated(conn, err)
|
conn.Router.ConnectionMaker.ConnectionTerminated(conn, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (conn *LocalConnection) forwarderCrypto() *OverlayCrypto {
|
|
||||||
if !conn.Router.UsingPassword() {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
name := conn.local.NameByte
|
|
||||||
return &OverlayCrypto{
|
|
||||||
Dec: NewNaClDecryptor(conn.SessionKey, conn.outbound),
|
|
||||||
Enc: NewNaClEncryptor(name, conn.SessionKey, conn.outbound, false),
|
|
||||||
EncDF: NewNaClEncryptor(name, conn.SessionKey, conn.outbound, true),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (conn *LocalConnection) sendOverlayControlMessage(tag byte, msg []byte) error {
|
func (conn *LocalConnection) sendOverlayControlMessage(tag byte, msg []byte) error {
|
||||||
return conn.sendProtocolMsg(ProtocolMsg{ProtocolTag(tag), msg})
|
return conn.sendProtocolMsg(ProtocolMsg{ProtocolTag(tag), msg})
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -507,7 +507,7 @@ type fastDatapathForwarder struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (fastdp fastDatapathOverlay) MakeForwarder(params ForwarderParams) (OverlayForwarder, error) {
|
func (fastdp fastDatapathOverlay) MakeForwarder(params ForwarderParams) (OverlayForwarder, error) {
|
||||||
if params.Crypto != nil {
|
if params.SessionKey != nil {
|
||||||
// No encryption suport in fastdp. The weaver main.go
|
// No encryption suport in fastdp. The weaver main.go
|
||||||
// is responsible for ensuring this doesn't happen.
|
// is responsible for ensuring this doesn't happen.
|
||||||
log.Fatal("Attempt to use FastDatapath with encryption")
|
log.Fatal("Attempt to use FastDatapath with encryption")
|
||||||
|
|||||||
+2
-2
@@ -46,8 +46,8 @@ type ForwarderParams struct {
|
|||||||
// Unique identifier for this connection
|
// Unique identifier for this connection
|
||||||
ConnUID uint64
|
ConnUID uint64
|
||||||
|
|
||||||
// Crypto bits. Nil if not encrypting
|
// Session key, if connection is encrypted; nil otherwise
|
||||||
Crypto *OverlayCrypto
|
SessionKey *[32]byte
|
||||||
|
|
||||||
// Function to send a control message to the counterpart
|
// Function to send a control message to the counterpart
|
||||||
// forwarder.
|
// forwarder.
|
||||||
|
|||||||
+7
-3
@@ -344,11 +344,15 @@ type controlMessage struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (sleeve *SleeveOverlay) MakeForwarder(params ForwarderParams) (OverlayForwarder, error) {
|
func (sleeve *SleeveOverlay) MakeForwarder(params ForwarderParams) (OverlayForwarder, error) {
|
||||||
|
name := sleeve.localPeer.NameByte
|
||||||
var crypto OverlayCrypto
|
var crypto OverlayCrypto
|
||||||
if params.Crypto != nil {
|
if params.SessionKey != nil {
|
||||||
crypto = *params.Crypto
|
crypto = OverlayCrypto{
|
||||||
|
Dec: NewNaClDecryptor(params.SessionKey, params.Outbound),
|
||||||
|
Enc: NewNaClEncryptor(name, params.SessionKey, params.Outbound, false),
|
||||||
|
EncDF: NewNaClEncryptor(name, params.SessionKey, params.Outbound, true),
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
name := sleeve.localPeer.NameByte
|
|
||||||
crypto = OverlayCrypto{
|
crypto = OverlayCrypto{
|
||||||
Dec: NewNonDecryptor(),
|
Dec: NewNonDecryptor(),
|
||||||
Enc: NewNonEncryptor(name),
|
Enc: NewNonEncryptor(name),
|
||||||
|
|||||||
Reference in new issue
Block a user