package discovery import ( "sync" "git.loafle.net/overflow_scanner/probe/discovery/types" uuid "github.com/satori/go.uuid" ) type ofDiscoveryRequest struct { requestID string requesterID string requestType types.DiscoveryRequestType params []interface{} dequeue chan bool timeout bool } func (dr *ofDiscoveryRequest) RequestID() string { return dr.requestID } func (dr *ofDiscoveryRequest) RequesterID() string { return dr.requesterID } func (dr *ofDiscoveryRequest) RequestType() types.DiscoveryRequestType { return dr.requestType } func (dr *ofDiscoveryRequest) Params() []interface{} { return dr.params } func (dr *ofDiscoveryRequest) release() { releaseDiscoveryRequest(dr) } var discoveryRequestPool sync.Pool func retainDiscoveryRequest(requesterID string, requestType types.DiscoveryRequestType, params ...interface{}) *ofDiscoveryRequest { v := discoveryRequestPool.Get() var dr *ofDiscoveryRequest if v == nil { dr = &ofDiscoveryRequest{} } else { dr = v.(*ofDiscoveryRequest) } dr.requestID = uuid.NewV4().String() dr.requesterID = requesterID dr.requestType = requestType dr.params = params dr.dequeue = make(chan bool, 1) dr.timeout = false return dr } func releaseDiscoveryRequest(dr *ofDiscoveryRequest) { dr.requestID = "" dr.requesterID = "" dr.requestType = types.DiscoveryRequestTypeNone dr.params = nil close(dr.dequeue) dr.dequeue = nil dr.timeout = false discoveryRequestPool.Put(dr) }