cloudflare/cloudflared

Public

mirrored from https://github.com/cloudflare/cloudflaredAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
11cbff4ff763fb10bd165e1f5a02bddf9016519d

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

cmd/cloudflared/app_forward_service.go

51lines · modecode

1package main
2
3import (
4 "github.com/rs/zerolog"
5
6 "github.com/cloudflare/cloudflared/cmd/cloudflared/access"
7 "github.com/cloudflare/cloudflared/config"
8)
9
10// ForwardServiceType is used to identify what kind of overwatch service this is
11const ForwardServiceType = "forward"
12
13// ForwarderService is used to wrap the access package websocket forwarders
14// into a service model for the overwatch package.
15// it also holds a reference to the config object that represents its state
16type ForwarderService struct {
17 forwarder config.Forwarder
18 shutdown chan struct{}
19 log *zerolog.Logger
20}
21
22// NewForwardService creates a new forwarder service
23func NewForwardService(f config.Forwarder, log *zerolog.Logger) *ForwarderService {
24 return &ForwarderService{forwarder: f, shutdown: make(chan struct{}, 1), log: log}
25}
26
27// Name is used to figure out this service is related to the others (normally the addr it binds to)
28// e.g. localhost:78641 or 127.0.0.1:2222 since this is a websocket forwarder
29func (s *ForwarderService) Name() string {
30 return s.forwarder.Listener
31}
32
33// Type is used to identify what kind of overwatch service this is
34func (s *ForwarderService) Type() string {
35 return ForwardServiceType
36}
37
38// Hash is used to figure out if this forwarder is the unchanged or not from the config file updates
39func (s *ForwarderService) Hash() string {
40 return s.forwarder.Hash()
41}
42
43// Shutdown stops the websocket listener
44func (s *ForwarderService) Shutdown() {
45 s.shutdown <- struct{}{}
46}
47
48// Run is the run loop that is started by the overwatch service
49func (s *ForwarderService) Run() error {
50 return access.StartForwarder(s.forwarder, s.shutdown, s.log)
51}
52