@@ -101,11 +101,15 @@ type FlowServer struct {
101101
102102// OnMessage event
103103func (c * FlowServerWebSocketConn ) OnMessage (client ws.Speaker , m ws.Message ) {
104- f , err := flow .FromData (m .Bytes (client .GetClientProtocol ()))
105- if err != nil {
104+ // rawmessage at this point
105+ b , _ := m .Bytes (ws .RawProtocol )
106+
107+ var f flow.Flow
108+ if err := f .Unmarshal (b ); err != nil {
106109 logging .GetLogger ().Errorf ("Error while parsing flow: %s" , err )
107110 return
108111 }
112+
109113 logging .GetLogger ().Debugf ("New flow from Websocket connection: %+v" , f )
110114 if len (c .ch ) >= c .maxFlowBufferSize {
111115 c .numOfLostFlows ++
@@ -118,7 +122,7 @@ func (c *FlowServerWebSocketConn) OnMessage(client ws.Speaker, m ws.Message) {
118122 return
119123 }
120124
121- c .ch <- f
125+ c .ch <- & f
122126}
123127
124128// Serve starts a WebSocket flow server
@@ -161,8 +165,8 @@ func (c *FlowServerUDPConn) Serve(ch chan *flow.Flow, quit chan struct{}, wg *sy
161165 logging .GetLogger ().Errorf ("Error while reading: %s" , err )
162166 }
163167
164- f , err := flow .FromData ( data [ 0 : n ])
165- if err != nil {
168+ var f flow.Flow
169+ if err := f . Unmarshal ( data [ 0 : n ]); err != nil {
166170 logging .GetLogger ().Errorf ("Error while parsing flow: %s" , err )
167171 continue
168172 }
@@ -178,7 +182,7 @@ func (c *FlowServerUDPConn) Serve(ch chan *flow.Flow, quit chan struct{}, wg *sy
178182 }
179183 return
180184 }
181- ch <- f
185+ ch <- & f
182186 }
183187 }
184188 }()
@@ -202,13 +206,13 @@ func NewFlowServerUDPConn(addr string, port int) (*FlowServerUDPConn, error) {
202206 return & FlowServerUDPConn {conn : conn , maxFlowBufferSize : flowsMax }, err
203207}
204208
205- func (s * FlowServer ) storeFlows (flows [] * flow.Flow ) {
206- if len (flows ) > 0 {
209+ func (s * FlowServer ) storeFlows (flows * flow.FlowArray ) {
210+ if len (flows . Flows ) > 0 {
207211 if s .storage != nil {
208- if err := s .storage .StoreFlows (flows ); err != nil {
212+ if err := s .storage .StoreFlows (flows . Flows ); err != nil {
209213 logging .GetLogger ().Error (err )
210214 } else {
211- logging .GetLogger ().Debugf ("%d flows stored" , len (flows ))
215+ logging .GetLogger ().Debugf ("%d flows stored" , len (flows . Flows ))
212216 }
213217 }
214218
@@ -228,21 +232,21 @@ func (s *FlowServer) Start() {
228232 dlTimer := time .NewTicker (s .bulkInsertDeadline )
229233 defer dlTimer .Stop ()
230234
231- var flowBuffer [] * flow.Flow
232- defer s .storeFlows (flowBuffer )
235+ var flowArray flow.FlowArray
236+ defer s .storeFlows (& flowArray )
233237
234238 for {
235239 select {
236240 case <- s .quit :
237241 return
238242 case <- dlTimer .C :
239- s .storeFlows (flowBuffer )
240- flowBuffer = flowBuffer [:0 ]
243+ s .storeFlows (& flowArray )
244+ flowArray . Flows = flowArray . Flows [:0 ]
241245 case f := <- s .ch :
242- flowBuffer = append (flowBuffer , f )
243- if len (flowBuffer ) >= s .bulkInsert {
244- s .storeFlows (flowBuffer )
245- flowBuffer = flowBuffer [:0 ]
246+ flowArray . Flows = append (flowArray . Flows , f )
247+ if len (flowArray . Flows ) >= s .bulkInsert {
248+ s .storeFlows (& flowArray )
249+ flowArray . Flows = flowArray . Flows [:0 ]
246250 }
247251 }
248252 }
0 commit comments