@@ -17,8 +17,6 @@ import (
1717 "sync/atomic"
1818 "time"
1919
20- "github.com/huandu/go-clone"
21-
2220 "github.com/p4gefau1t/trojan-go/common"
2321 "github.com/p4gefau1t/trojan-go/config"
2422 "github.com/p4gefau1t/trojan-go/log"
@@ -50,7 +48,6 @@ type Server struct {
5048 cancel context.CancelFunc
5149 underlay tunnel.Server
5250 nextHTTP int32
53- setNextHTTPOnce sync.Once
5451 portOverrider map [string ]int
5552}
5653
@@ -107,8 +104,7 @@ func (s *Server) acceptLoop() {
107104 if s .verifySNI && ! matched {
108105 return nil , common .NewError ("sni mismatched: " + hello .ServerName + ", expected: " + s .sni )
109106 }
110- keyPairCopied := clone .Clone (& s .keyPair [0 ]).(* tls.Certificate )
111- return keyPairCopied , nil
107+ return & s .keyPair [0 ], nil
112108 },
113109 }
114110
@@ -209,6 +205,8 @@ func (s *Server) AcceptPacket(tunnel.Tunnel) (tunnel.PacketConn, error) {
209205
210206func (s * Server ) checkKeyPairLoop (checkRate time.Duration , keyPath string , certPath string , password string ) {
211207 var lastKeyBytes , lastCertBytes []byte
208+ ticker := time .NewTicker (checkRate )
209+
212210 for {
213211 log .Debug ("checking cert..." )
214212 keyBytes , err := ioutil .ReadFile (keyPath )
@@ -234,11 +232,13 @@ func (s *Server) checkKeyPairLoop(checkRate time.Duration, keyPath string, certP
234232 lastKeyBytes = keyBytes
235233 lastCertBytes = certBytes
236234 }
235+
237236 select {
238- case <- time . After ( checkRate ) :
237+ case <- ticker . C :
239238 continue
240239 case <- s .ctx .Done ():
241240 log .Debug ("exiting" )
241+ ticker .Stop ()
242242 return
243243 }
244244 }
0 commit comments