refactor: Connections don't need to know about overlay crypto

This commit is contained in:
Matthias Radestock committed 2015-11-07 16:10:00 +00:00
1 parent 519aef86fa
commit 006262ed8f
4 files changed
+11 -20

No files matched your search

+1 -14
View File
@@ -196,7 +196,7 @@ func (conn *LocalConnection) run(actionChan <-chan ConnectionAction, finished ch
RemoteAddr: conn.TCPConn.RemoteAddr().(*net.TCPAddr),
Outbound: conn.outbound,
ConnUID: conn.uid,
Crypto: conn.forwarderCrypto(),
SessionKey: conn.SessionKey,
SendControlMessage: conn.sendOverlayControlMessage,
Features: intro.Features,
}
@@ -390,19 +390,6 @@ func (conn *LocalConnection) shutdown(err error) {
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 {
return conn.sendProtocolMsg(ProtocolMsg{ProtocolTag(tag), msg})
}
+1 -1
View File
@@ -507,7 +507,7 @@ type fastDatapathForwarder struct {
}
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
// is responsible for ensuring this doesn't happen.
log.Fatal("Attempt to use FastDatapath with encryption")
+2 -2
View File
@@ -46,8 +46,8 @@ type ForwarderParams struct {
// Unique identifier for this connection
ConnUID uint64
// Crypto bits. Nil if not encrypting
Crypto *OverlayCrypto
// Session key, if connection is encrypted; nil otherwise
SessionKey *[32]byte
// Function to send a control message to the counterpart
// forwarder.
+7 -3
View File
@@ -344,11 +344,15 @@ type controlMessage struct {
}
func (sleeve *SleeveOverlay) MakeForwarder(params ForwarderParams) (OverlayForwarder, error) {
name := sleeve.localPeer.NameByte
var crypto OverlayCrypto
if params.Crypto != nil {
crypto = *params.Crypto
if params.SessionKey != nil {
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 {
name := sleeve.localPeer.NameByte
crypto = OverlayCrypto{
Dec: NewNonDecryptor(),
Enc: NewNonEncryptor(name),