mirror of
https://github.com/status-im/status-go.git
synced 2025-01-09 22:26:30 +00:00
707221954f
This change adds adds an ability to use different source of time for whisper: when envelope is created it is used to set expiry to track when envelope needs to be expired This time is then used to check validity of the envelope when it is received. Currently If we receive an envelope that is sent from future - peer will get disconnected. If envelope that was received has an expiry less then now it will be simply dropped, if expiry is less than now + 10*2 seconds peer will get dropped. So, it is clear that whisper depends on time. And any time we get a skew with peers that is > 20s reliability will be grealy reduced. In this change another source of time for whisper will be used. This time source will use ntp servers from pool.ntp.org to compute offset. When whisper queries time - this offset will be added/substracted from current time. Query is executed every 2 mins, queries 5 different servers, cut offs min and max and the computes mean value. pool.ntp.org is resolved to different servers and according to documentation you will rarely hit the same. Closes: #687
70 lines
2.2 KiB
Go
70 lines
2.2 KiB
Go
// Copyright 2012 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package ipv4
|
|
|
|
import (
|
|
"net"
|
|
"syscall"
|
|
|
|
"golang.org/x/net/internal/socket"
|
|
)
|
|
|
|
// BUG(mikio): On Windows, the ReadFrom and WriteTo methods of RawConn
|
|
// are not implemented.
|
|
|
|
// A packetHandler represents the IPv4 datagram handler.
|
|
type packetHandler struct {
|
|
*net.IPConn
|
|
*socket.Conn
|
|
rawOpt
|
|
}
|
|
|
|
func (c *packetHandler) ok() bool { return c != nil && c.IPConn != nil && c.Conn != nil }
|
|
|
|
// ReadFrom reads an IPv4 datagram from the endpoint c, copying the
|
|
// datagram into b. It returns the received datagram as the IPv4
|
|
// header h, the payload p and the control message cm.
|
|
func (c *packetHandler) ReadFrom(b []byte) (h *Header, p []byte, cm *ControlMessage, err error) {
|
|
if !c.ok() {
|
|
return nil, nil, nil, syscall.EINVAL
|
|
}
|
|
return c.readFrom(b)
|
|
}
|
|
|
|
func slicePacket(b []byte) (h, p []byte, err error) {
|
|
if len(b) < HeaderLen {
|
|
return nil, nil, errHeaderTooShort
|
|
}
|
|
hdrlen := int(b[0]&0x0f) << 2
|
|
return b[:hdrlen], b[hdrlen:], nil
|
|
}
|
|
|
|
// WriteTo writes an IPv4 datagram through the endpoint c, copying the
|
|
// datagram from the IPv4 header h and the payload p. The control
|
|
// message cm allows the datagram path and the outgoing interface to be
|
|
// specified. Currently only Darwin and Linux support this. The cm
|
|
// may be nil if control of the outgoing datagram is not required.
|
|
//
|
|
// The IPv4 header h must contain appropriate fields that include:
|
|
//
|
|
// Version = <must be specified>
|
|
// Len = <must be specified>
|
|
// TOS = <must be specified>
|
|
// TotalLen = <must be specified>
|
|
// ID = platform sets an appropriate value if ID is zero
|
|
// FragOff = <must be specified>
|
|
// TTL = <must be specified>
|
|
// Protocol = <must be specified>
|
|
// Checksum = platform sets an appropriate value if Checksum is zero
|
|
// Src = platform sets an appropriate value if Src is nil
|
|
// Dst = <must be specified>
|
|
// Options = optional
|
|
func (c *packetHandler) WriteTo(h *Header, p []byte, cm *ControlMessage) error {
|
|
if !c.ok() {
|
|
return syscall.EINVAL
|
|
}
|
|
return c.writeTo(h, p, cm)
|
|
}
|