From dfb00ceffe8955bee96db846ab0840b57029333e Mon Sep 17 00:00:00 2001 From: Dmitry Shihovtsev Date: Thu, 21 Jul 2016 17:14:56 +0600 Subject: [PATCH 1/4] Removed 1ms latency --- lib/p2p.go | 3 ++- lib/packet.go | 5 ++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/p2p.go b/lib/p2p.go index 1cc474b8..7a55b45c 100644 --- a/lib/p2p.go +++ b/lib/p2p.go @@ -5,13 +5,14 @@ import ( //"crypto/md5" "crypto/rand" "fmt" - "gopkg.in/yaml.v2" "io/ioutil" "net" "runtime" "strings" "sync" "time" + + "gopkg.in/yaml.v2" ) type MessageHandler func(message *P2PMessage, src_addr *net.UDPAddr) diff --git a/lib/packet.go b/lib/packet.go index c29df65d..de139ff5 100644 --- a/lib/packet.go +++ b/lib/packet.go @@ -16,13 +16,13 @@ import ( "encoding/binary" "errors" "fmt" - "github.com/mdlayher/ethernet" "io" "net" + + "github.com/mdlayher/ethernet" //"runtime" //"crypto/md5" "sync" - "time" ) type PacketType int @@ -146,7 +146,6 @@ func (p *PTPCloud) handlePacketIPv4(contents []byte, proto int) { d = append(d, sum[:]...) d = append(d, contents...) */ - time.Sleep(time.Millisecond * 1) msg := CreateNencP2PMessage(p.Crypter, contents, uint16(proto), 1, 1, 1) p.SendTo(f.Destination, msg) return From 437c28cfb01fd8081776d65fe54de80a0c3603c1 Mon Sep 17 00:00:00 2001 From: Mikhail Savochkin Date: Mon, 25 Jul 2016 02:04:27 +0600 Subject: [PATCH 2/4] Proxy attributes extraction for forwarders --- lib/net.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/net.go b/lib/net.go index df70d128..386a529f 100644 --- a/lib/net.go +++ b/lib/net.go @@ -61,6 +61,10 @@ func P2PMessageHeaderFromBytes(bytes []byte) (*P2PMessageHeader, error) { return result, nil } +func GetProxyAttributes(bytes []byte) (uint16, uint16) { + return binary.BigEndian.Uint16(bytes[8:10]), binary.BigEndian.Uint16(bytes[2:4]) +} + func (v *P2PMessage) Serialize() []byte { v.Header.SerializedLen = uint16(len(v.Data)) Log(TRACE, "--- Serialize P2PMessage header.SerializedLen : %d", v.Header.SerializedLen) @@ -331,3 +335,11 @@ func (uc *PTPNet) SendMessage(msg *P2PMessage, dst_addr *net.UDPAddr) (int, erro } return n, nil } + +func (uc *PTPNet) SendRawBytes(bytes []byte, dst_addr *net.UDPAddr) (int, error) { + n, err := uc.conn.WriteToUDP(bytes, dst_addr) + if err != nil { + return 0, err + } + return n, nil +} From 4b68b2e36f6a245f7516079221dd7890b66407ef Mon Sep 17 00:00:00 2001 From: Mikhail Savochkin Date: Tue, 26 Jul 2016 23:43:20 +0600 Subject: [PATCH 3/4] Reviewed error logs --- lib/crypto.go | 2 +- lib/peer.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/crypto.go b/lib/crypto.go index df0b5144..76eedd1e 100644 --- a/lib/crypto.go +++ b/lib/crypto.go @@ -35,7 +35,7 @@ func (c Crypto) EnrichKeyValues(ckey CryptoKey, key, datetime string) CryptoKey // Default value is +1 hour ckey.Until = ckey.Until.Add(60 * time.Minute) if err != nil { - Log(ERROR, "Failed to parse TTL. Falling back to default value of 1 hour") + Log(WARNING, "Failed to parse TTL. Falling back to default value of 1 hour") } else { ckey.Until = time.Unix(i, 0) } diff --git a/lib/peer.go b/lib/peer.go index 080a84ac..764c032f 100644 --- a/lib/peer.go +++ b/lib/peer.go @@ -60,7 +60,7 @@ func (np *NetworkPeer) Run(ptpc *PTPCloud) { } err := callback(ptpc) if err != nil { - Log(ERROR, "Peer %s: %v", np.ID, err) + Log(WARNING, "Peer %s: %v", np.ID, err) } time.Sleep(time.Millisecond * 500) } @@ -323,7 +323,7 @@ func (np *NetworkPeer) TestConnection(ptpc *PTPCloud, endpoint *net.UDPAddr) boo msg := CreateTestP2PMessage(ptpc.Crypter, "TEST", 0) conn, err := net.DialUDP("udp4", nil, endpoint) if err != nil { - Log(ERROR, "%v", err) + Log(DEBUG, "%v", err) return false } ser := msg.Serialize() @@ -340,7 +340,7 @@ func (np *NetworkPeer) TestConnection(ptpc *PTPCloud, endpoint *net.UDPAddr) boo var buf [4096]byte s, _, err := conn.ReadFromUDP(buf[0:]) if err != nil { - Log(ERROR, "%v", err) + Log(DEBUG, "%v", err) conn.Close() return false } From 39acea0b6cf446185b0bdd07bc4f3cffb0c655a9 Mon Sep 17 00:00:00 2001 From: Mikhail Savochkin Date: Tue, 26 Jul 2016 23:45:46 +0600 Subject: [PATCH 4/4] Fixes #183 : Safe show command --- instance.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/instance.go b/instance.go index 31c32414..ff15dddb 100644 --- a/instance.go +++ b/instance.go @@ -285,26 +285,34 @@ func (p *Procedures) Show(args *RunArgs, resp *Response) error { resp.ExitCode = 0 if exists { if args.IP != "" { + swarm.PTP.PeersLock.Lock() for _, peer := range swarm.PTP.NetworkPeers { if peer.PeerLocalIP.String() == args.IP { if peer.State == ptp.P_CONNECTED { resp.ExitCode = 0 resp.Output = "Integrated with " + args.IP + swarm.PTP.PeersLock.Unlock() + runtime.Gosched() return nil } } } + swarm.PTP.PeersLock.Unlock() + runtime.Gosched() resp.ExitCode = 1 resp.Output = "Not yet integrated with " + args.IP return nil } else { resp.Output = "< Peer ID >\t< IP >\t< Endpoint >\t< HW >\n" + swarm.PTP.PeersLock.Lock() for _, peer := range swarm.PTP.NetworkPeers { resp.Output = resp.Output + peer.ID + "\t" resp.Output = resp.Output + peer.PeerLocalIP.String() + "\t" resp.Output = resp.Output + peer.Endpoint.String() + "\t" resp.Output = resp.Output + peer.PeerHW.String() + "\n" } + swarm.PTP.PeersLock.Unlock() + runtime.Gosched() } } else { resp.Output = "Specified environment was not found: " + args.Hash