Clean up unnecessary code
This commit is contained in:
parent
620fd31b10
commit
33b88c570d
@ -18,31 +18,18 @@ 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") }
|
// Create gob encoder with connection as io.Writer
|
||||||
// Concurrently handle connection
|
encoder := gob.NewEncoder(connection)
|
||||||
go func(conn net.Conn) {
|
// Encode key into connection
|
||||||
// Create gob encoder with connection as io.Writer
|
err = encoder.Encode(key)
|
||||||
encoder := gob.NewEncoder(conn)
|
if err != nil { log.Fatal().Err(err).Msg("Error encoding key") }
|
||||||
// Encode key into connection
|
return senderAddr
|
||||||
err := encoder.Encode(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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user