Skip to content

Commit

Permalink
Merge pull request #186 from subutai-io/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
crioto authored Jul 27, 2016
2 parents e509d3f + a45aa31 commit 5151df0
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 8 deletions.
8 changes: 8 additions & 0 deletions instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
12 changes: 12 additions & 0 deletions lib/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
3 changes: 2 additions & 1 deletion lib/p2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 2 additions & 3 deletions lib/packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions lib/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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()
Expand All @@ -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
}
Expand Down

0 comments on commit 5151df0

Please sign in to comment.