mirror of
https://github.com/KusakabeShi/EtherGuard-VPN.git
synced 2024-11-21 14:53:08 +01:00
Fix wrong NTP result
This commit is contained in:
parent
999fb6d641
commit
9886e2bf09
@ -149,16 +149,16 @@ SendAddr | Packet send address for `*sock` mode(client mode)
|
||||
|
||||
<a name="IType"></a>IType | Description
|
||||
-----------|:-----
|
||||
dummy | Dymmy interface, drop any packet received. You need this if you want to setup it as a relay node.
|
||||
stdio | Wrtie to stdout,read from stdin. <br>Required parameter: `MacAddrPrefix` && `L2HeaderMode`
|
||||
udpsock | Read/Write the raw packet to an udp socket.<br>Required parameter: `RecvAddr` && `SendAddr`
|
||||
tcpsock | Read/Write the raw packet to a tcp socket. <br>Required parameter: `RecvAddr` \|\| `SendAddr`
|
||||
unixsock | Read/Write the raw packet to an unix socket(SOCK_STREAM mode).<br>Required parameter: `RecvAddr` \|\| `SendAddr`
|
||||
udpsock | Read/Write the raw packet to an unix socket(SOCK_DGRAM mode)<br>Required parameter: `RecvAddr` \|\| `SendAddr`
|
||||
udpsock | Read/Write the raw packet to an unix socket(SOCK_SEQPACKET mode).<br>Required parameter: `RecvAddr` \|\| `SendAddr`
|
||||
fd | Read/Write the raw packet to specific file descriptor.<br>Required parameter: None. But require environment variable `EG_FD_RX` && `EG_FD_TX`
|
||||
vpp | Integrate to VPP by libmemif. <br>Required parameter: `Name` && `VPPIFaceID` && `VPPBridgeID` && `MacAddrPrefix` && `MTU`
|
||||
tap | Read/Write to tap device from linux.<br>Required parameter: `Name` && `MacAddrPrefix` && `MTU`<br>Optional Parameter:`IPv4CIDR` , `IPv6CIDR` , `IPv6LLPrefix`
|
||||
dummy | Dymmy interface, drop any packet received. You need this if you want to setup it as a relay node.
|
||||
stdio | Wrtie to stdout,read from stdin. <br>Required parameter: `MacAddrPrefix` && `L2HeaderMode`
|
||||
udpsock | Read/Write the raw packet to an udp socket.<br>Required parameter: `RecvAddr` && `SendAddr`
|
||||
tcpsock | Read/Write the raw packet to a tcp socket. <br>Required parameter: `RecvAddr` \|\| `SendAddr`
|
||||
unixsock | Read/Write the raw packet to an unix socket(SOCK_STREAM mode).<br>Required parameter: `RecvAddr` \|\| `SendAddr`
|
||||
unixgramsock | Read/Write the raw packet to an unix socket(SOCK_DGRAM mode)<br>Required parameter: `RecvAddr` \|\| `SendAddr`
|
||||
unixpacketsock | Read/Write the raw packet to an unix socket(SOCK_SEQPACKET mode).<br>Required parameter: `RecvAddr` \|\| `SendAddr`
|
||||
fd | Read/Write the raw packet to specific file descriptor.<br>Required parameter: None. But require environment variable `EG_FD_RX` && `EG_FD_TX`
|
||||
vpp | Integrate to VPP by libmemif. <br>Required parameter: `Name` && `VPPIFaceID` && `VPPBridgeID` && `MacAddrPrefix` && `MTU`
|
||||
tap | Read/Write to tap device from linux.<br>Required parameter: `Name` && `MacAddrPrefix` && `MTU`<br>Optional Parameter:`IPv4CIDR` , `IPv6CIDR` , `IPv6LLPrefix`
|
||||
|
||||
<a name="L2HeaderMode"></a>L2HeaderMode | Description
|
||||
---------------|:-----
|
||||
|
@ -159,17 +159,17 @@ SendAddr | 連線地址,VPN網路收到的東西丟去這個地址。僅
|
||||
[L2HeaderMode](#L2HeaderMode) | 僅限 `stdio` 生效。debug用途,有三種模式
|
||||
|
||||
<a name="IType"></a>IType | Description
|
||||
-----------|:-----
|
||||
dummy | 收到的封包直接丟棄,但幫忙轉發。作為中繼節點,本身不加入網路使用
|
||||
stdio | 收到的封包丟stdout,stdin進來的資料丟入vpn網路,debug用途<br>需要參數: `MacAddrPrefix` && `L2HeaderMode`
|
||||
udpsock | 收到的封包丟去一個udp socket<br>需要參數: `RecvAddr` && `SendAddr`
|
||||
tcpsock | 收到的封包丟去一個tcp socket<br>需要參數: `RecvAddr` \|\| `SendAddr`
|
||||
unixsock | 收到的封包丟去一個unix socket(SOCK_STREAM 模式)<br>需要參數: `RecvAddr` \|\| `SendAddr`
|
||||
udpsock | 收到的封包丟去一個unix socket(SOCK_DGRAM 模式)<br>需要參數: `RecvAddr` \|\| `SendAddr`
|
||||
udpsock | 收到的封包丟去一個unix socket(SOCK_SEQPACKET 模式)<br>需要參數: `RecvAddr` \|\| `SendAddr`
|
||||
fd | 收到的封包丟去一個特定的file descriptor<br>需要參數: 無. 但是使用環境變數 `EG_FD_RX` && `EG_FD_TX` 來指定
|
||||
vpp | 使用libmemif使vpp加入VPN網路<br>需要參數: `Name` && `VPPIFaceID` && `VPPBridgeID` && `MacAddrPrefix` && `MTU`
|
||||
tap | Linux的tap設備。讓linux加入VPN網路<br>需要參數: `Name` && `MacAddrPrefix` && `MTU`<br>可選參數:`IPv4CIDR` , `IPv6CIDR` , `IPv6LLPrefix`
|
||||
---------------|:-----
|
||||
dummy | 收到的封包直接丟棄,但幫忙轉發。作為中繼節點,本身不加入網路使用
|
||||
stdio | 收到的封包丟stdout,stdin進來的資料丟入vpn網路,debug用途<br>需要參數: `MacAddrPrefix` && `L2HeaderMode`
|
||||
udpsock | 收到的封包丟去一個udp socket<br>需要參數: `RecvAddr` && `SendAddr`
|
||||
tcpsock | 收到的封包丟去一個tcp socket<br>需要參數: `RecvAddr` \|\| `SendAddr`
|
||||
unixsock | 收到的封包丟去一個unix socket(SOCK_STREAM 模式)<br>需要參數: `RecvAddr` \|\| `SendAddr`
|
||||
unixgramsock | 收到的封包丟去一個unix socket(SOCK_DGRAM 模式)<br>需要參數: `RecvAddr` \|\| `SendAddr`
|
||||
unixpacketsock | 收到的封包丟去一個unix socket(SOCK_SEQPACKET 模式)<br>需要參數: `RecvAddr` \|\| `SendAddr`
|
||||
fd | 收到的封包丟去一個特定的file descriptor<br>需要參數: 無. 但是使用環境變數 `EG_FD_RX` && `EG_FD_TX` 來指定
|
||||
vpp | 使用libmemif使vpp加入VPN網路<br>需要參數: `Name` && `VPPIFaceID` && `VPPBridgeID` && `MacAddrPrefix` && `MTU`
|
||||
tap | Linux的tap設備。讓linux加入VPN網路<br>需要參數: `Name` && `MacAddrPrefix` && `MTU`<br>可選參數:`IPv4CIDR` , `IPv6CIDR` , `IPv6LLPrefix`
|
||||
|
||||
<a name="L2HeaderMode"></a>L2HeaderMode | Description
|
||||
---------------|:-----
|
||||
|
10
path/ntp.go
10
path/ntp.go
@ -13,6 +13,7 @@ import (
|
||||
var forever = time.Hour * 99999
|
||||
|
||||
func (g *IG) InitNTP() {
|
||||
g.ntp_init_t = time.Now()
|
||||
if g.ntp_info.UseNTP {
|
||||
if len(g.ntp_info.Servers) == 0 {
|
||||
g.ntp_info.UseNTP = false
|
||||
@ -72,12 +73,15 @@ func (g *IG) SyncTimeMultiple(count int) {
|
||||
g.ntp_servers.Sort(func(a *orderedmap.Pair, b *orderedmap.Pair) bool {
|
||||
return a.Value().(ntp.Response).RTT < b.Value().(ntp.Response).RTT
|
||||
})
|
||||
results := make([]time.Duration, count)
|
||||
for _, url := range g.ntp_servers.Keys() {
|
||||
results := make([]time.Duration, 0, count)
|
||||
for index, url := range g.ntp_servers.Keys() {
|
||||
val, has := g.ntp_servers.Get(url)
|
||||
if !has {
|
||||
continue
|
||||
}
|
||||
if index >= count {
|
||||
break
|
||||
}
|
||||
result := val.(ntp.Response)
|
||||
if result.RTT < forever {
|
||||
results = append(results, result.ClockOffset)
|
||||
@ -117,7 +121,7 @@ func (g *IG) SyncTime(url string, timeout time.Duration) {
|
||||
fmt.Println("NTP: NTP server :" + url + "\tFailed :" + err.Error())
|
||||
}
|
||||
g.ntp_servers.Set(url, ntp.Response{
|
||||
RTT: forever,
|
||||
RTT: forever + time.Since(g.ntp_init_t),
|
||||
})
|
||||
}
|
||||
g.ntp_wg.Done()
|
||||
|
@ -49,6 +49,7 @@ type IG struct {
|
||||
|
||||
ntp_wg sync.WaitGroup
|
||||
ntp_info mtypes.NTPInfo
|
||||
ntp_init_t time.Time
|
||||
ntp_offset time.Duration
|
||||
ntp_servers orderedmap.OrderedMap // serverurl:lentancy
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user