|
1 | 1 | package network |
2 | 2 |
|
3 | | -import "github.com/layou233/zbproxy/v3/common/jsonx" |
| 3 | +import ( |
| 4 | + "time" |
| 5 | + |
| 6 | + "github.com/layou233/zbproxy/v3/common/jsonx" |
| 7 | +) |
4 | 8 |
|
5 | 9 | type InboundSocketOptions struct { |
6 | | - KeepAlivePeriod jsonx.Duration `json:",omitempty"` |
7 | | - Mark int `json:",omitempty"` |
8 | | - SendThrough string `json:",omitempty"` |
9 | | - TCPCongestion string `json:",omitempty"` |
10 | | - TCPFastOpen bool `json:",omitempty"` |
11 | | - MultiPathTCP bool `json:",omitempty"` |
| 10 | + keepAliveOptions |
| 11 | + Mark int `json:",omitempty"` |
| 12 | + SendThrough string `json:",omitempty"` |
| 13 | + TCPCongestion string `json:",omitempty"` |
| 14 | + TCPFastOpen bool `json:",omitempty"` |
| 15 | + MultiPathTCP bool `json:",omitempty"` |
12 | 16 | } |
13 | 17 |
|
14 | 18 | type OutboundSocketOptions struct { |
15 | | - KeepAlivePeriod jsonx.Duration `json:",omitempty"` |
16 | | - Mark int `json:",omitempty"` |
17 | | - Interface string `json:",omitempty"` |
18 | | - SendThrough string `json:",omitempty"` |
19 | | - TCPCongestion string `json:",omitempty"` |
20 | | - TCPFastOpen bool `json:",omitempty"` |
21 | | - MultiPathTCP bool `json:",omitempty"` |
| 19 | + keepAliveOptions |
| 20 | + Mark int `json:",omitempty"` |
| 21 | + Interface string `json:",omitempty"` |
| 22 | + SendThrough string `json:",omitempty"` |
| 23 | + TCPCongestion string `json:",omitempty"` |
| 24 | + TCPFastOpen bool `json:",omitempty"` |
| 25 | + MultiPathTCP bool `json:",omitempty"` |
| 26 | +} |
| 27 | + |
| 28 | +type keepAliveOptions struct { |
| 29 | + KeepAliveIdle jsonx.Duration `json:",omitempty"` |
| 30 | + KeepAliveInterval jsonx.Duration `json:",omitempty"` |
| 31 | + KeepAliveCount int `json:",omitempty"` |
| 32 | +} |
| 33 | + |
| 34 | +func (o *keepAliveOptions) KeepAliveConfig() (c KeepAliveConfig) { |
| 35 | + c = KeepAliveConfig{ |
| 36 | + Idle: time.Duration(o.KeepAliveIdle), |
| 37 | + Interval: time.Duration(o.KeepAliveInterval), |
| 38 | + Count: o.KeepAliveCount, |
| 39 | + } |
| 40 | + if c.Idle > 0 || c.Interval > 0 || c.Count > 0 { |
| 41 | + c.Enable = true |
| 42 | + } |
| 43 | + return |
22 | 44 | } |
23 | 45 |
|
24 | 46 | func ConvertLegacyOutboundOptions(inbound *InboundSocketOptions) *OutboundSocketOptions { |
25 | 47 | if inbound == nil { |
26 | 48 | return nil |
27 | 49 | } |
28 | 50 | return &OutboundSocketOptions{ |
29 | | - KeepAlivePeriod: inbound.KeepAlivePeriod, |
30 | | - Mark: inbound.Mark, |
31 | | - SendThrough: inbound.SendThrough, |
32 | | - TCPCongestion: inbound.TCPCongestion, |
33 | | - TCPFastOpen: inbound.TCPFastOpen, |
34 | | - MultiPathTCP: inbound.MultiPathTCP, |
| 51 | + keepAliveOptions: keepAliveOptions{ |
| 52 | + KeepAliveIdle: inbound.KeepAliveIdle, |
| 53 | + KeepAliveInterval: inbound.KeepAliveInterval, |
| 54 | + KeepAliveCount: inbound.KeepAliveCount, |
| 55 | + }, |
| 56 | + Mark: inbound.Mark, |
| 57 | + SendThrough: inbound.SendThrough, |
| 58 | + TCPCongestion: inbound.TCPCongestion, |
| 59 | + TCPFastOpen: inbound.TCPFastOpen, |
| 60 | + MultiPathTCP: inbound.MultiPathTCP, |
35 | 61 | } |
36 | 62 | } |
0 commit comments