本文整理匯總了Golang中udppacket.Packet類的典型用法代碼示例。如果您正苦於以下問題:Golang Packet類的具體用法?Golang Packet怎麽用?Golang Packet使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Packet類的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: onData
/**
* 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
}
示例2: onData
/**
* 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
}
示例3: WriteToClientProxy
func (utAddId *UT_ADD_ID) WriteToClientProxy(p *udppacket.Packet) *udppacket.Packet {
utAddId.LOG.Print("ut_add_id_module WriteToClientProxy")
utAddId.lock.Lock()
defer utAddId.lock.Unlock()
if p.ModulesCtx[utAddId.Index] == nil {
p.ModulesCtx[utAddId.Index] = new(CTX_UT_ADD_ID)
tunnelId := utAddId.Ut.GetNewTunnelId()
p.ChangeTunnelId(tunnelId)
}
return p
}
示例4: WritePacketToClientProxy
/**
* 處理服務器網關寫原始數據
* 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()
}
}
示例5: processSendPacket
/***********************************************************
* 處理發送給tunnel的數據包
* - 功能:將新數據包加入發送隊列,重傳的數據包,更新狀態
***********************************************************/
func (utNack *UT_NACK) processSendPacket(p *udppacket.Packet) {
/***** SEND *****/
if wrapper, ok := utNack.SendMap[p.TunnelId]; ok {
wrapper.p = p
wrapper.status = WRAPPER_STATUS_RTR
} else { // 新包,發送隊列中不存在該packet的wrapper
wrapper = new(PACKET_WRAPPER)
wrapper.p = p
wrapper.status = WRAPPER_STATUS_SENDED
utNack.SendMap[p.TunnelId] = wrapper
}
if p.TunnelId > utNack.maxSendId {
utNack.maxSendId = p.TunnelId
}
/***** RECV *****/
otherTunnelId, flag := utNack.getNackPacketTunnelId()
p.ChangeOtherTunnelId(otherTunnelId)
p.ChangePacketType(flag)
}
示例6: processRecvPacket
/*************************************************************
* 處理從tunnel收到的數據包
* - 功能:根據包的類型,處理相應的OtherTunnelId的數據包,是還沒有到
* 該數據包,還是需要重傳順便對需要確認的數據包進行確認釋放
************************************************************/
func (utNack *UT_NACK) processRecvPacket(p *udppacket.Packet) {
utNack.LOG.Println("processRecvPacket")
status := p.GetPacketType()
utNack.LOG.Println("tunnelId", p.TunnelId, "packetType", status)
/***** SEND *****/
if status&udppacket.PACK_ACK == udppacket.PACK_ACK {
utNack.LOG.Println("ack")
utNack.ackPackets(p.OtherTunnelId)
}
/***** RECV *****/
wrapper, ok := utNack.RecvMap[p.TunnelId]
if ok {
wrapper.status = WRAPPER_STATUS_RECVED
} else {
wrapper = new(PACKET_WRAPPER)
wrapper.status = WRAPPER_STATUS_RECVED
}
utNack.RecvMap[p.TunnelId] = wrapper
if p.TunnelId > utNack.maxRecvId {
utNack.maxRecvId = p.TunnelId
}
}
示例7: WriteToClientProxy
func (utWriter *UT_WRITER) WriteToClientProxy(p *udppacket.Packet) *udppacket.Packet {
utWriter.Ut.WriteData(p.GetPacket())
return nil
}