Example #1
0
func (srv *Service) muxMatcher() {
	var mux frames.ChannelDialer
	for {
		select {
		case newDialer := <-srv.newMuxConn:
			if mux != nil {
				srv.log.Printf("Closing old mux connection %v", mux.GetInfo())
				mux.Close()
			}
			mux = newDialer
			srv.log.Printf("Installed new mux connection %v", mux.GetInfo())
		case badDialer := <-srv.badMuxConn:
			if mux == badDialer {
				srv.log.Printf("Closing bad mux connection %v", mux.GetInfo())
				mux.Close()
				mux = nil
			}
		case clientConn := <-srv.newClientConn:
			if mux == nil {
				srv.log.Printf("Disconnected new client from %v: no mux client connected", clientConn.RemoteAddr())
				clientConn.Close()
				continue
			}
			go srv.negotiateClientConn(mux, clientConn)
		}
	}
}