hnakra/cmd/router/srvhnakra/hnakra.go

35 lines
756 B
Go
Raw Normal View History

2023-05-25 16:08:56 -06:00
package srvhnakra
import "log"
import "fmt"
import "net"
import "crypto/tls"
import "hnakra/router"
import "hnakra/config"
type Server struct {
underlying net.Listener
Config config.Config
Router *router.Router
}
func (server *Server) ListenAndServe () (err error) {
server.underlying, err = tls.Listen (
"tcp", fmt.Sprint(":", server.Config.RouterPort()),
config.TLSConfigFor(server.Config))
if err != nil { return err }
log.Println(".// router on", server.underlying.Addr())
for {
conn, err := server.underlying.Accept()
if err != nil { return err }
log.Println("-=E incoming connection from", conn.RemoteAddr())
server.Router.Accept(conn)
}
}
func (server *Server) Close () error {
return server.underlying.Close()
}