Exemplo n.º 1
0
/**
 * tunnel call
 *
 **/
func onData(p *udppacket.Packet) int {
	LOG.Println("tcp2udp onData")
	p.LogPacket()
	// getsession
	s, ok := idSessionMap[p.SessionId]
	if !ok {
		return -1
	}
	if p.Length == 0 {
		releaseSession(s.GetId(), false)
	}
	// processNewPacketFromServerProxy
	s.Slock.Lock()
	s.ProcessNewPacketFromServerProxy(p)
	// getNextDataToSend

	for {
		p := s.GetNextRecvDataToSend()
		if p == nil {
			break
		}
		processWrite(s, p.GetPacket())

	}
	s.Slock.Unlock()
	return 0
}
Exemplo n.º 2
0
/**
 * tunnel call
 **/
func onData(p *udppacket.Packet) int {
	LOG.Println("udp2tcp onData")
	p.LogPacket()
	// close packet
	if p.Length == 0 {
		releaseSession(p.SessionId, false)
		return 1
	}
	s := getSession(p.SessionId)
	if s == nil {
		return -1
	}
	//LOG.Println("udp2tcp check")
	s.Slock.Lock()
	s.ProcessNewPacketFromClientProxy(p)
	for {
		p := s.GetNextRecvDataToSend()
		if p == nil {
			LOG.Println("send data nil")
			break
		}
		processWrite(s, p.GetPacket())

	}
	s.Slock.Unlock()
	return 0
}
Exemplo n.º 3
0
/**
 * 处理服务器网关写原始数据
 * rawData: 原始数据,但是前面预留了96(ut.Reserved)字节的头空间
 **/
func (ut *UDPTunnel) WritePacketToClientProxy(p *udppacket.Packet) {
	//log.Println("udptunnel WritePacketToClientProxy")
	var sendP *udppacket.Packet = p
	size := len(ut.Handlers)
	for i := 0; i < size; i++ {
		sendP = ut.Handlers[i].WriteToClientProxy(sendP)
		if sendP == nil {
			break
		}
	}
	if sendP != nil {
		ut.send <- sendP.GetPacket()
	}
}
Exemplo n.º 4
0
func (utWriter *UT_WRITER) WriteToClientProxy(p *udppacket.Packet) *udppacket.Packet {
	utWriter.Ut.WriteData(p.GetPacket())
	return nil
}