Clean up unnecessary code
This commit is contained in:
parent
620fd31b10
commit
33b88c570d
@ -18,33 +18,20 @@ func ReceiverKeyExchange(key *rsa.PublicKey) string {
|
|||||||
if err != nil { log.Fatal().Err(err).Msg("Error starting listener") }
|
if err != nil { log.Fatal().Err(err).Msg("Error starting listener") }
|
||||||
// Create string for sender address
|
// Create string for sender address
|
||||||
var senderAddr string
|
var senderAddr string
|
||||||
// Create channel to send break signal
|
|
||||||
breakChannel := make(chan bool)
|
|
||||||
for {
|
for {
|
||||||
// Accept connection on listener
|
// Accept connection on listener
|
||||||
connection, err := listener.Accept()
|
connection, err := listener.Accept()
|
||||||
|
if err != nil { log.Fatal().Err(err).Msg("Error accepting connections") }
|
||||||
// Get sender address and store it in senderAddr
|
// Get sender address and store it in senderAddr
|
||||||
senderAddr = connection.RemoteAddr().String()
|
senderAddr = connection.RemoteAddr().String()
|
||||||
if err != nil { log.Fatal().Err(err).Msg("Error accepting connections") }
|
|
||||||
// Concurrently handle connection
|
|
||||||
go func(conn net.Conn) {
|
|
||||||
// Create gob encoder with connection as io.Writer
|
// Create gob encoder with connection as io.Writer
|
||||||
encoder := gob.NewEncoder(conn)
|
encoder := gob.NewEncoder(connection)
|
||||||
// Encode key into connection
|
// Encode key into connection
|
||||||
err := encoder.Encode(key)
|
err = encoder.Encode(key)
|
||||||
if err != nil { log.Fatal().Err(err).Msg("Error encoding key") }
|
if err != nil { log.Fatal().Err(err).Msg("Error encoding key") }
|
||||||
// Send signal to breakChannel
|
|
||||||
breakChannel <- true
|
|
||||||
}(connection)
|
|
||||||
// Wait for break signal
|
|
||||||
select {
|
|
||||||
// When break signal arrives
|
|
||||||
case _ = <-breakChannel:
|
|
||||||
// Return sender address
|
|
||||||
return senderAddr
|
return senderAddr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Exchange keys with receiver
|
// Exchange keys with receiver
|
||||||
func SenderKeyExchange(receiverIP string) *rsa.PublicKey {
|
func SenderKeyExchange(receiverIP string) *rsa.PublicKey {
|
||||||
|
Reference in New Issue
Block a user