hnakra/cmd/router/srvhnakra/hnakra.go
2023-05-26 13:05:22 -04:00

35 lines
763 B
Go

package srvhnakra
import "log"
import "fmt"
import "net"
import "crypto/tls"
import "hnakra/router"
import "hnakra/router/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()
}