github.com/GeniusesGroup/libgo@v0.0.0-20220929090155-5ff932cb408e/srpc/frame-open-stream.go (about) 1 /* For license and copyright information please see LEGAL file in repository */ 2 3 package srpc 4 5 import ( 6 "../protocol" 7 "../syllab" 8 ) 9 10 /* 11 type openStreamFrame struct { 12 ProtocolID uint16 // protocol ID usage is like TCP||UDP ports that indicate payload protocol. 13 SerErrID uint64 // Service or Error 14 CompressID uint64 15 TotalPacket uint32 // Expected packets count that send over this stream! 16 DataLength uint64 17 Weight protocol.ConnectionWeight 18 } 19 */ 20 type openStreamFrame []byte 21 22 func (f openStreamFrame) ProtocolID() uint16 { return syllab.GetUInt16(f, 0) } 23 func (f openStreamFrame) SerErrID() uint64 { return syllab.GetUInt64(f, 2) } 24 func (f openStreamFrame) CompressID() uint64 { return syllab.GetUInt64(f, 10) } 25 func (f openStreamFrame) Weight() protocol.ConnectionWeight { return protocol.ConnectionWeight(f[10]) } 26 func (f openStreamFrame) NextFrame() []byte { return f[18:] } 27 28 // setStreamSettings set stream settings like time sensitive use in VoIP, IPTV, ... 29 func openStream(conn protocol.Connection, frame openStreamFrame) (err protocol.Error) { 30 // TODO::: allow multiple settings set?? 31 32 // Check server supported requested protocol 33 var ProtocolID = protocol.NetworkApplicationProtocolID(frame.ProtocolID()) 34 var protocolHandler protocol.NetworkApplicationHandler = protocol.App.GetNetworkApplicationHandler(ProtocolID) 35 if protocolHandler == nil { 36 // Send response or just ignore packet 37 // TODO::: DDOS!!?? 38 return 39 } 40 41 // Dropping packets is preferable to waiting for packets delayed due to retransmissions. 42 // Developer can ask to complete data for offline usage after first data usage. 43 return 44 }