diff --git a/server.go b/server.go index a550352..d1c2c2d 100644 --- a/server.go +++ b/server.go @@ -3,6 +3,8 @@ package ircd import ( + "crypto/rand" + "crypto/tls" "fmt" "net" "os" @@ -148,7 +150,7 @@ func (sv *Server) listen(laddr string) { os.Exit(-1) } for { - time.Sleep(1 * time.Millisecond) + time.Sleep(10 * time.Millisecond) conn, err := listen.Accept() if err != nil { xlog.Error(err.Error()) @@ -160,6 +162,26 @@ func (sv *Server) listen(laddr string) { } func (sv *Server) listenTls(laddr string) { + cert, err := tls.LoadX509KeyPair("cert/server.pem", "cert/server.key") + if err != nil { + xlog.Fatal(err.Error()) + } + cfg := tls.Config{Certificates: []tls.Certificate{cert}} + cfg.Rand = rand.Reader + listen, err := tls.Listen("tcp", laddr, &cfg) + if err != nil { + xlog.Fatal(err.Error()) + } + for { + time.Sleep(10 * time.Millisecond) + conn, err := listen.Accept() + if err != nil { + xlog.Error(err.Error()) + } else { + NewRemoteClient(sv, conn) + sv.connectionsCount++ + } + } } func (sv *Server) dispatcher() (err error) {