// Proxy processes and forwards packets from src to dst
Proxy processes and forwards packets from src to dst
// Proxy processes and forwards packets from src to dst
func Proxy(src, dst *Peer) {
	if src == nil {
		data := []byte{
			0, ToClientAccessDenied,
			AccessDeniedServerFail, 0, 0, 0, 0,
		}
		_, err := dst.Send(rudp.Pkt{Data: data})
		if err != nil {
			log.Print(err)
		}
		dst.SendDisco(0, true)
		dst.Close()
		processLeave(dst)
		return
	} else if dst == nil {
		src.SendDisco(0, true)
		src.Close()
		return
	}
	for {
		pkt, err := src.Recv()
		if !src.Forward() {
			return
		} else if !dst.Forward() {
			break
		}
		if err != nil {
			if err == rudp.ErrClosed {
				msg := src.Addr().String() + " disconnected"
				if src.TimedOut() {
					msg += " (timed out)"
				}
				log.Print(msg)
				if !src.IsSrv() {
					connectedPeersMu.Lock()
					connectedPeers--
					connectedPeersMu.Unlock()
					processLeave(src)
				}
				break
			}
			log.Print(err)
			continue
		}
		if processPktCommand(src, dst, &pkt) {
			continue
		}
		if _, err := dst.Send(pkt); err != nil {
			log.Print(err)
		}
	}
	dst.SendDisco(0, true)
	dst.Close()
}
func Proxy ( src , dst * Peer ) { if src == nil { data := [ ] byte { 0 , ToClientAccessDenied , AccessDeniedServerFail , 0 , 0 , 0 , 0 , } _ , err := dst . Send ( rudp . Pkt { Data : data } ) if err != nil { log . Print ( err ) } dst . SendDisco ( 0 , true ) dst . Close ( ) processLeave ( dst ) return } else if dst == nil { src . SendDisco ( 0 , true ) src . Close ( ) return } for { pkt , err := src . Recv ( ) if ! src . Forward ( ) { return } else if ! dst . Forward ( ) { break } if err != nil { if err == rudp . ErrClosed { msg := src . Addr ( ) . String ( ) + " " if src . TimedOut ( ) { msg += " " } log . Print ( msg ) if ! src . IsSrv ( ) { connectedPeersMu . Lock ( ) connectedPeers -- connectedPeersMu . Unlock ( ) processLeave ( src ) } break } log . Print ( err ) continue } if processPktCommand ( src , dst , & pkt ) { continue } if _ , err := dst . Send ( pkt ) ; err != nil { log . Print ( err ) } } dst . SendDisco ( 0 , true ) dst . Close ( ) }
Proxy processes and forwards packets from src to dst
Proxy processes and forwards packets from src to dst
// Process // Forward