-
Notifications
You must be signed in to change notification settings - Fork 17
/
wiretap_service.go
64 lines (56 loc) · 1.67 KB
/
wiretap_service.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright 2023 Princess Beef Heavy Industries LLC
// SPDX-License-Identifier: MIT
package daemon
import (
"github.com/pb33f/libopenapi"
"github.com/pb33f/libopenapi/datamodel/high/v3"
"github.com/pb33f/ranch/bus"
"github.com/pb33f/ranch/model"
"github.com/pb33f/ranch/service"
"github.com/pb33f/wiretap/controls"
"net/http"
"time"
)
const (
WiretapServiceChan = "wiretap"
WiretapBroadcastChan = "wiretap-broadcast"
IncomingHttpRequest = "incoming-http-request"
)
type WiretapService struct {
transport *http.Transport
document libopenapi.Document
docModel *v3.Document
serviceCore service.FabricServiceCore
broadcastChan *bus.Channel
bus bus.EventBus
controlsStore bus.BusStore
transactionStore bus.BusStore
}
func NewWiretapService(document libopenapi.Document) *WiretapService {
storeManager := bus.GetBus().GetStoreManager()
controlsStore := storeManager.CreateStore(controls.ControlServiceChan)
transactionStore := storeManager.CreateStore(WiretapServiceChan)
tr := &http.Transport{
MaxIdleConns: 20,
IdleConnTimeout: 30 * time.Second,
}
m, _ := document.BuildV3Model()
return &WiretapService{
document: document,
docModel: &m.Model,
transport: tr,
controlsStore: controlsStore,
transactionStore: transactionStore,
}
}
func (ws *WiretapService) HandleServiceRequest(request *model.Request, core service.FabricServiceCore) {
switch request.RequestCommand {
case IncomingHttpRequest:
ws.handleHttpRequest(request)
default:
core.HandleUnknownRequest(request)
}
}
func (ws *WiretapService) HandleHttpRequest(request *model.Request) {
ws.handleHttpRequest(request)
}