probe/discovery/discovery-request.go

72 lines
1.4 KiB
Go
Raw Normal View History

2018-08-29 12:04:23 +00:00
package discovery
import (
"sync"
"git.loafle.net/overflow_scanner/probe/discovery/types"
2018-09-13 13:05:05 +00:00
uuid "github.com/satori/go.uuid"
2018-08-29 12:04:23 +00:00
)
type ofDiscoveryRequest struct {
2018-09-13 13:05:05 +00:00
requestID string
2018-08-29 12:04:23 +00:00
requesterID string
requestType types.DiscoveryRequestType
params []interface{}
2018-08-30 12:56:32 +00:00
dequeue chan bool
timeout bool
2018-08-29 12:04:23 +00:00
}
2018-09-13 13:05:05 +00:00
func (dr *ofDiscoveryRequest) RequestID() string {
return dr.requestID
}
2018-08-29 12:04:23 +00:00
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
2018-08-30 12:56:32 +00:00
func retainDiscoveryRequest(requesterID string, requestType types.DiscoveryRequestType, params ...interface{}) *ofDiscoveryRequest {
2018-08-29 12:04:23 +00:00
v := discoveryRequestPool.Get()
var dr *ofDiscoveryRequest
if v == nil {
dr = &ofDiscoveryRequest{}
} else {
dr = v.(*ofDiscoveryRequest)
}
2018-09-13 13:05:05 +00:00
dr.requestID = uuid.NewV4().String()
2018-08-29 12:04:23 +00:00
dr.requesterID = requesterID
dr.requestType = requestType
dr.params = params
dr.dequeue = make(chan bool, 1)
dr.timeout = false
return dr
}
func releaseDiscoveryRequest(dr *ofDiscoveryRequest) {
2018-09-13 13:05:05 +00:00
dr.requestID = ""
2018-08-29 12:04:23 +00:00
dr.requesterID = ""
dr.requestType = types.DiscoveryRequestTypeNone
dr.params = nil
close(dr.dequeue)
dr.dequeue = nil
dr.timeout = false
discoveryRequestPool.Put(dr)
}