mirror of
https://github.com/KusakabeShi/EtherGuard-VPN.git
synced 2025-02-02 17:09:14 +01:00
version check in supernode
This commit is contained in:
parent
7951ba2f6a
commit
72e4ebc91d
@ -6,11 +6,13 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Nonnegative integer ID of vertex
|
||||||
|
type Vertex uint16
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Boardcast Vertex = math.MaxUint32 - iota // Normal boardcast, boardcast with route table
|
Boardcast Vertex = math.MaxUint16 - iota // Normal boardcast, boardcast with route table
|
||||||
ControlMessage Vertex = math.MaxUint32 - iota // p2p mode: boardcast to every know keer and prevent dup/ super mode: send to supernode
|
ControlMessage Vertex = math.MaxUint16 - iota // p2p mode: boardcast to every know keer and prevent dup/ super mode: send to supernode
|
||||||
PingMessage Vertex = math.MaxUint32 - iota // boardsact to every know peer but don't transit
|
SuperNodeMessage Vertex = math.MaxUint16 - iota
|
||||||
SuperNodeMessage Vertex = math.MaxUint32 - iota
|
|
||||||
Special_NodeID Vertex = SuperNodeMessage
|
Special_NodeID Vertex = SuperNodeMessage
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -18,6 +20,7 @@ type EdgeConfig struct {
|
|||||||
Interface InterfaceConf
|
Interface InterfaceConf
|
||||||
NodeID Vertex
|
NodeID Vertex
|
||||||
NodeName string
|
NodeName string
|
||||||
|
DefaultTTL uint8
|
||||||
PrivKey string
|
PrivKey string
|
||||||
ListenPort int
|
ListenPort int
|
||||||
LogLevel LoggerInfo
|
LogLevel LoggerInfo
|
||||||
@ -36,7 +39,7 @@ type SuperConfig struct {
|
|||||||
RePushConfigInterval float64
|
RePushConfigInterval float64
|
||||||
StatePassword string
|
StatePassword string
|
||||||
GraphRecalculateSetting GraphRecalculateSetting
|
GraphRecalculateSetting GraphRecalculateSetting
|
||||||
Peers []PeerInfo
|
Peers []SuperPeerInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
type InterfaceConf struct {
|
type InterfaceConf struct {
|
||||||
@ -59,6 +62,13 @@ type PeerInfo struct {
|
|||||||
Static bool
|
Static bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type SuperPeerInfo struct {
|
||||||
|
NodeID Vertex
|
||||||
|
Name string
|
||||||
|
PubKey string
|
||||||
|
PSKey string
|
||||||
|
}
|
||||||
|
|
||||||
type LoggerInfo struct {
|
type LoggerInfo struct {
|
||||||
LogLevel string
|
LogLevel string
|
||||||
LogTransit bool
|
LogTransit bool
|
||||||
@ -67,17 +77,12 @@ type LoggerInfo struct {
|
|||||||
LogNTP bool
|
LogNTP bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Nonnegative integer ID of vertex
|
|
||||||
type Vertex uint32
|
|
||||||
|
|
||||||
func (v *Vertex) ToString() string {
|
func (v *Vertex) ToString() string {
|
||||||
switch *v {
|
switch *v {
|
||||||
case Boardcast:
|
case Boardcast:
|
||||||
return "B"
|
return "B"
|
||||||
case ControlMessage:
|
case ControlMessage:
|
||||||
return "C"
|
return "C"
|
||||||
case PingMessage:
|
|
||||||
return "P"
|
|
||||||
case SuperNodeMessage:
|
case SuperNodeMessage:
|
||||||
return "S"
|
return "S"
|
||||||
default:
|
default:
|
||||||
@ -136,6 +141,7 @@ type HTTP_Peerinfo struct {
|
|||||||
PSKey string
|
PSKey string
|
||||||
Connurl map[string]bool
|
Connurl map[string]bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type HTTP_Peers map[string]HTTP_Peerinfo
|
type HTTP_Peers map[string]HTTP_Peerinfo
|
||||||
|
|
||||||
const chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
const chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||||
|
@ -87,14 +87,15 @@ type Device struct {
|
|||||||
indexTable IndexTable
|
indexTable IndexTable
|
||||||
cookieChecker CookieChecker
|
cookieChecker CookieChecker
|
||||||
|
|
||||||
MsgCount uint32
|
|
||||||
IsSuperNode bool
|
IsSuperNode bool
|
||||||
ID config.Vertex
|
ID config.Vertex
|
||||||
|
DefaultTTL uint8
|
||||||
graph *path.IG
|
graph *path.IG
|
||||||
l2fib sync.Map
|
l2fib sync.Map
|
||||||
LogLevel config.LoggerInfo
|
LogLevel config.LoggerInfo
|
||||||
DRoute config.DynamicRouteInfo
|
DRoute config.DynamicRouteInfo
|
||||||
DupData fixed_time_cache.Cache
|
DupData fixed_time_cache.Cache
|
||||||
|
Version string
|
||||||
|
|
||||||
pool struct {
|
pool struct {
|
||||||
messageBuffers *WaitPool
|
messageBuffers *WaitPool
|
||||||
@ -309,7 +310,7 @@ func (device *Device) SetPrivateKey(sk NoisePrivateKey) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDevice(tapDevice tap.Device, id config.Vertex, bind conn.Bind, logger *Logger, graph *path.IG, IsSuperNode bool, configpath string, econfig *config.EdgeConfig, sconfig *config.SuperConfig, superevents *path.SUPER_Events) *Device {
|
func NewDevice(tapDevice tap.Device, id config.Vertex, bind conn.Bind, logger *Logger, graph *path.IG, IsSuperNode bool, configpath string, econfig *config.EdgeConfig, sconfig *config.SuperConfig, superevents *path.SUPER_Events, version string) *Device {
|
||||||
device := new(Device)
|
device := new(Device)
|
||||||
device.state.state = uint32(deviceStateDown)
|
device.state.state = uint32(deviceStateDown)
|
||||||
device.closed = make(chan struct{})
|
device.closed = make(chan struct{})
|
||||||
@ -328,6 +329,7 @@ func NewDevice(tapDevice tap.Device, id config.Vertex, bind conn.Bind, logger *L
|
|||||||
device.IsSuperNode = IsSuperNode
|
device.IsSuperNode = IsSuperNode
|
||||||
device.ID = id
|
device.ID = id
|
||||||
device.graph = graph
|
device.graph = graph
|
||||||
|
device.Version = version
|
||||||
|
|
||||||
device.rate.limiter.Init()
|
device.rate.limiter.Init()
|
||||||
device.indexTable.Init()
|
device.indexTable.Init()
|
||||||
@ -350,6 +352,7 @@ func NewDevice(tapDevice tap.Device, id config.Vertex, bind conn.Bind, logger *L
|
|||||||
device.Event_Supernode_OK = make(chan struct{}, 4)
|
device.Event_Supernode_OK = make(chan struct{}, 4)
|
||||||
device.LogLevel = econfig.LogLevel
|
device.LogLevel = econfig.LogLevel
|
||||||
device.ResetConnInterval = device.EdgeConfig.ResetConnInterval
|
device.ResetConnInterval = device.EdgeConfig.ResetConnInterval
|
||||||
|
device.DefaultTTL = econfig.DefaultTTL
|
||||||
go device.RoutineSetEndpoint()
|
go device.RoutineSetEndpoint()
|
||||||
go device.RoutineRegister()
|
go device.RoutineRegister()
|
||||||
go device.RoutineSendPing()
|
go device.RoutineSendPing()
|
||||||
@ -383,25 +386,32 @@ func NewDevice(tapDevice tap.Device, id config.Vertex, bind conn.Bind, logger *L
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (device *Device) LookupPeerIDAtConfig(pk NoisePublicKey) (ID config.Vertex, err error) {
|
func (device *Device) LookupPeerIDAtConfig(pk NoisePublicKey) (ID config.Vertex, err error) {
|
||||||
var peerlist []config.PeerInfo
|
|
||||||
if device.IsSuperNode {
|
if device.IsSuperNode {
|
||||||
|
var peerlist []config.SuperPeerInfo
|
||||||
if device.SuperConfig == nil {
|
if device.SuperConfig == nil {
|
||||||
return 0, errors.New("Superconfig is nil")
|
return 0, errors.New("Superconfig is nil")
|
||||||
}
|
}
|
||||||
peerlist = device.SuperConfig.Peers
|
peerlist = device.SuperConfig.Peers
|
||||||
|
pkstr := PubKey2Str(pk)
|
||||||
|
for _, peerinfo := range peerlist {
|
||||||
|
if peerinfo.PubKey == pkstr {
|
||||||
|
return peerinfo.NodeID, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
|
var peerlist []config.PeerInfo
|
||||||
if device.EdgeConfig == nil {
|
if device.EdgeConfig == nil {
|
||||||
return 0, errors.New("EdgeConfig is nil")
|
return 0, errors.New("EdgeConfig is nil")
|
||||||
}
|
}
|
||||||
peerlist = device.EdgeConfig.Peers
|
peerlist = device.EdgeConfig.Peers
|
||||||
}
|
pkstr := PubKey2Str(pk)
|
||||||
|
for _, peerinfo := range peerlist {
|
||||||
pkstr := PubKey2Str(pk)
|
if peerinfo.PubKey == pkstr {
|
||||||
for _, peerinfo := range peerlist {
|
return peerinfo.NodeID, nil
|
||||||
if peerinfo.PubKey == pkstr {
|
}
|
||||||
return peerinfo.NodeID, nil
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0, errors.New("Peer not found in the config file.")
|
return 0, errors.New("Peer not found in the config file.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -471,9 +471,6 @@ func (peer *Peer) RoutineSequentialReceiver() {
|
|||||||
case config.Boardcast:
|
case config.Boardcast:
|
||||||
should_receive = true
|
should_receive = true
|
||||||
should_transfer = true
|
should_transfer = true
|
||||||
case config.PingMessage:
|
|
||||||
peer.LastPingReceived = time.Now()
|
|
||||||
should_process = true
|
|
||||||
case config.SuperNodeMessage:
|
case config.SuperNodeMessage:
|
||||||
should_process = true
|
should_process = true
|
||||||
case config.ControlMessage:
|
case config.ControlMessage:
|
||||||
@ -533,7 +530,7 @@ func (peer *Peer) RoutineSequentialReceiver() {
|
|||||||
if packet_type != path.NornalPacket {
|
if packet_type != path.NornalPacket {
|
||||||
if device.LogLevel.LogControl {
|
if device.LogLevel.LogControl {
|
||||||
if peer.GetEndpointDstStr() != "" {
|
if peer.GetEndpointDstStr() != "" {
|
||||||
fmt.Println("Control: Received MID:" + strconv.Itoa(int(EgHeader.GetMessageID())) + " From:" + peer.GetEndpointDstStr() + " " + device.sprint_received(packet_type, elem.packet[path.EgHeaderLen:]))
|
fmt.Println("Control: Received From:" + peer.GetEndpointDstStr() + " " + device.sprint_received(packet_type, elem.packet[path.EgHeaderLen:]))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
err = device.process_received(packet_type, peer, elem.packet[path.EgHeaderLen:])
|
err = device.process_received(packet_type, peer, elem.packet[path.EgHeaderLen:])
|
||||||
|
@ -33,10 +33,8 @@ func (device *Device) SendPacket(peer *Peer, packet []byte, offset int) {
|
|||||||
if device.LogLevel.LogControl {
|
if device.LogLevel.LogControl {
|
||||||
EgHeader, _ := path.NewEgHeader(packet[:path.EgHeaderLen])
|
EgHeader, _ := path.NewEgHeader(packet[:path.EgHeaderLen])
|
||||||
if EgHeader.GetUsage() != path.NornalPacket {
|
if EgHeader.GetUsage() != path.NornalPacket {
|
||||||
device.MsgCount += 1
|
|
||||||
EgHeader.SetMessageID(device.MsgCount)
|
|
||||||
if peer.GetEndpointDstStr() != "" {
|
if peer.GetEndpointDstStr() != "" {
|
||||||
fmt.Println("Control: Send MID:" + strconv.Itoa(int(device.MsgCount)) + " To:" + peer.GetEndpointDstStr() + " " + device.sprint_received(EgHeader.GetUsage(), packet[path.EgHeaderLen:]))
|
fmt.Println("Control: Send To:" + peer.GetEndpointDstStr() + " " + device.sprint_received(EgHeader.GetUsage(), packet[path.EgHeaderLen:]))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -145,7 +143,7 @@ func (device *Device) process_received(msg_type path.Usage, peer *Peer, body []b
|
|||||||
}
|
}
|
||||||
case path.PingPacket:
|
case path.PingPacket:
|
||||||
if content, err := path.ParsePingMsg(body); err == nil {
|
if content, err := path.ParsePingMsg(body); err == nil {
|
||||||
return device.process_ping(content)
|
return device.process_ping(peer, content)
|
||||||
}
|
}
|
||||||
case path.PongPacket:
|
case path.PongPacket:
|
||||||
if content, err := path.ParsePongMsg(body); err == nil {
|
if content, err := path.ParsePongMsg(body); err == nil {
|
||||||
@ -207,13 +205,29 @@ func (device *Device) sprint_received(msg_type path.Usage, body []byte) (ret str
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (device *Device) server_process_RegisterMsg(peer *Peer, content path.RegisterMsg) error {
|
func (device *Device) server_process_RegisterMsg(peer *Peer, content path.RegisterMsg) error {
|
||||||
|
UpdateErrorMsg := path.UpdateErrorMsg{
|
||||||
|
Node_id: peer.ID,
|
||||||
|
Action: path.NoAction,
|
||||||
|
ErrorCode: 0,
|
||||||
|
ErrorMsg: "",
|
||||||
|
}
|
||||||
if peer.ID != content.Node_id {
|
if peer.ID != content.Node_id {
|
||||||
UpdateErrorMsg := path.UpdateErrorMsg{
|
UpdateErrorMsg = path.UpdateErrorMsg{
|
||||||
Node_id: peer.ID,
|
Node_id: peer.ID,
|
||||||
Action: path.Shutdown,
|
Action: path.Shutdown,
|
||||||
ErrorCode: 401,
|
ErrorCode: 401,
|
||||||
ErrorMsg: "Your node ID is not match with our nodeID",
|
ErrorMsg: "Your node ID is not match with our registered nodeID",
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if content.Version != device.Version {
|
||||||
|
UpdateErrorMsg = path.UpdateErrorMsg{
|
||||||
|
Node_id: peer.ID,
|
||||||
|
Action: path.Shutdown,
|
||||||
|
ErrorCode: 400,
|
||||||
|
ErrorMsg: "Your version is not match with our version: " + device.Version,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if UpdateErrorMsg.Action != path.NoAction {
|
||||||
body, err := path.GetByte(&UpdateErrorMsg)
|
body, err := path.GetByte(&UpdateErrorMsg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -221,11 +235,11 @@ func (device *Device) server_process_RegisterMsg(peer *Peer, content path.Regist
|
|||||||
buf := make([]byte, path.EgHeaderLen+len(body))
|
buf := make([]byte, path.EgHeaderLen+len(body))
|
||||||
header, err := path.NewEgHeader(buf[:path.EgHeaderLen])
|
header, err := path.NewEgHeader(buf[:path.EgHeaderLen])
|
||||||
header.SetSrc(device.ID)
|
header.SetSrc(device.ID)
|
||||||
header.SetTTL(200)
|
header.SetTTL(device.DefaultTTL)
|
||||||
header.SetUsage(path.UpdateError)
|
header.SetUsage(path.UpdateError)
|
||||||
header.SetPacketLength(uint16(len(body)))
|
header.SetPacketLength(uint16(len(body)))
|
||||||
copy(buf[path.EgHeaderLen:], body)
|
copy(buf[path.EgHeaderLen:], body)
|
||||||
header.SetDst(config.ControlMessage)
|
header.SetDst(peer.ID)
|
||||||
device.SendPacket(peer, buf, MessageTransportOffsetContent)
|
device.SendPacket(peer, buf, MessageTransportOffsetContent)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -238,7 +252,8 @@ func (device *Device) server_process_Pong(content path.PongMsg) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (device *Device) process_ping(content path.PingMsg) error {
|
func (device *Device) process_ping(peer *Peer, content path.PingMsg) error {
|
||||||
|
peer.LastPingReceived = time.Now()
|
||||||
PongMSG := path.PongMsg{
|
PongMSG := path.PongMsg{
|
||||||
Src_nodeID: content.Src_nodeID,
|
Src_nodeID: content.Src_nodeID,
|
||||||
Dst_nodeID: device.ID,
|
Dst_nodeID: device.ID,
|
||||||
@ -254,7 +269,7 @@ func (device *Device) process_ping(content path.PingMsg) error {
|
|||||||
buf := make([]byte, path.EgHeaderLen+len(body))
|
buf := make([]byte, path.EgHeaderLen+len(body))
|
||||||
header, err := path.NewEgHeader(buf[:path.EgHeaderLen])
|
header, err := path.NewEgHeader(buf[:path.EgHeaderLen])
|
||||||
header.SetSrc(device.ID)
|
header.SetSrc(device.ID)
|
||||||
header.SetTTL(200)
|
header.SetTTL(device.DefaultTTL)
|
||||||
header.SetUsage(path.PongPacket)
|
header.SetUsage(path.PongPacket)
|
||||||
header.SetPacketLength(uint16(len(body)))
|
header.SetPacketLength(uint16(len(body)))
|
||||||
copy(buf[path.EgHeaderLen:], body)
|
copy(buf[path.EgHeaderLen:], body)
|
||||||
@ -285,7 +300,7 @@ func (device *Device) process_pong(peer *Peer, content path.PongMsg) error {
|
|||||||
buf := make([]byte, path.EgHeaderLen+len(body))
|
buf := make([]byte, path.EgHeaderLen+len(body))
|
||||||
header, err := path.NewEgHeader(buf[:path.EgHeaderLen])
|
header, err := path.NewEgHeader(buf[:path.EgHeaderLen])
|
||||||
header.SetSrc(device.ID)
|
header.SetSrc(device.ID)
|
||||||
header.SetTTL(200)
|
header.SetTTL(device.DefaultTTL)
|
||||||
header.SetUsage(path.QueryPeer)
|
header.SetUsage(path.QueryPeer)
|
||||||
header.SetPacketLength(uint16(len(body)))
|
header.SetPacketLength(uint16(len(body)))
|
||||||
copy(buf[path.EgHeaderLen:], body)
|
copy(buf[path.EgHeaderLen:], body)
|
||||||
@ -525,7 +540,7 @@ func (device *Device) RoutineRegister() {
|
|||||||
Node_id: device.ID,
|
Node_id: device.ID,
|
||||||
PeerStateHash: device.peers.Peer_state,
|
PeerStateHash: device.peers.Peer_state,
|
||||||
NhStateHash: device.graph.NhTableHash,
|
NhStateHash: device.graph.NhTableHash,
|
||||||
Name: device.EdgeConfig.NodeName,
|
Version: device.Version,
|
||||||
})
|
})
|
||||||
buf := make([]byte, path.EgHeaderLen+len(body))
|
buf := make([]byte, path.EgHeaderLen+len(body))
|
||||||
header, _ := path.NewEgHeader(buf[0:path.EgHeaderLen])
|
header, _ := path.NewEgHeader(buf[0:path.EgHeaderLen])
|
||||||
@ -610,7 +625,7 @@ func (device *Device) GeneratePingPacket(src_nodeID config.Vertex) ([]byte, erro
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
header.SetDst(config.PingMessage)
|
header.SetDst(config.ControlMessage)
|
||||||
header.SetTTL(0)
|
header.SetTTL(0)
|
||||||
header.SetSrc(device.ID)
|
header.SetSrc(device.ID)
|
||||||
header.SetUsage(path.PingPacket)
|
header.SetUsage(path.PingPacket)
|
||||||
@ -646,7 +661,7 @@ func (device *Device) process_RequestPeerMsg(content path.QueryPeerMsg) error {
|
|||||||
buf := make([]byte, path.EgHeaderLen+len(body))
|
buf := make([]byte, path.EgHeaderLen+len(body))
|
||||||
header, _ := path.NewEgHeader(buf[0:path.EgHeaderLen])
|
header, _ := path.NewEgHeader(buf[0:path.EgHeaderLen])
|
||||||
header.SetDst(config.ControlMessage)
|
header.SetDst(config.ControlMessage)
|
||||||
header.SetTTL(200)
|
header.SetTTL(device.DefaultTTL)
|
||||||
header.SetSrc(device.ID)
|
header.SetSrc(device.ID)
|
||||||
header.SetUsage(path.BoardcastPeer)
|
header.SetUsage(path.BoardcastPeer)
|
||||||
header.SetPacketLength(uint16(len(body)))
|
header.SetPacketLength(uint16(len(body)))
|
||||||
|
@ -262,7 +262,7 @@ func (device *Device) RoutineReadFromTUN() {
|
|||||||
EgBody.SetSrc(device.ID)
|
EgBody.SetSrc(device.ID)
|
||||||
EgBody.SetDst(dst_nodeID)
|
EgBody.SetDst(dst_nodeID)
|
||||||
EgBody.SetPacketLength(uint16(len(elem.packet) - path.EgHeaderLen))
|
EgBody.SetPacketLength(uint16(len(elem.packet) - path.EgHeaderLen))
|
||||||
EgBody.SetTTL(200)
|
EgBody.SetTTL(device.DefaultTTL)
|
||||||
EgBody.SetUsage(path.NornalPacket)
|
EgBody.SetUsage(path.NornalPacket)
|
||||||
|
|
||||||
if dst_nodeID != config.Boardcast {
|
if dst_nodeID != config.Boardcast {
|
||||||
|
@ -4,12 +4,13 @@ interface:
|
|||||||
vppifaceid: 1
|
vppifaceid: 1
|
||||||
vppbridgeid: 4242
|
vppbridgeid: 4242
|
||||||
macaddrprefix: AA:BB:CC:DD:EE
|
macaddrprefix: AA:BB:CC:DD:EE
|
||||||
mtu: 1400
|
mtu: 1404
|
||||||
recvaddr: 127.0.0.1:4001
|
recvaddr: 127.0.0.1:4001
|
||||||
sendaddr: 127.0.0.1:5001
|
sendaddr: 127.0.0.1:5001
|
||||||
l2headermode: kbdbg
|
l2headermode: kbdbg
|
||||||
nodeid: 1
|
nodeid: 1
|
||||||
nodename: Node01
|
nodename: Node01
|
||||||
|
defaultttl: 200
|
||||||
privkey: aABzjKhWdkFfQ29ZuijtMp1h1TNJe66SDCwvfmvQznw=
|
privkey: aABzjKhWdkFfQ29ZuijtMp1h1TNJe66SDCwvfmvQznw=
|
||||||
listenport: 3001
|
listenport: 3001
|
||||||
loglevel:
|
loglevel:
|
||||||
|
@ -4,12 +4,13 @@ interface:
|
|||||||
vppifaceid: 2
|
vppifaceid: 2
|
||||||
vppbridgeid: 4242
|
vppbridgeid: 4242
|
||||||
macaddrprefix: AA:BB:CC:DD:EE
|
macaddrprefix: AA:BB:CC:DD:EE
|
||||||
mtu: 1400
|
mtu: 1404
|
||||||
recvaddr: 127.0.0.1:4002
|
recvaddr: 127.0.0.1:4002
|
||||||
sendaddr: 127.0.0.1:5002
|
sendaddr: 127.0.0.1:5002
|
||||||
l2headermode: kbdbg
|
l2headermode: kbdbg
|
||||||
nodeid: 2
|
nodeid: 2
|
||||||
nodename: Node02
|
nodename: Node02
|
||||||
|
defaultttl: 200
|
||||||
privkey: UNZMzPX5fG/8yGC8edVj/ksF9N6ARRqdq7fqE/PD7ls=
|
privkey: UNZMzPX5fG/8yGC8edVj/ksF9N6ARRqdq7fqE/PD7ls=
|
||||||
listenport: 3002
|
listenport: 3002
|
||||||
loglevel:
|
loglevel:
|
||||||
|
@ -4,12 +4,13 @@ interface:
|
|||||||
vppifaceid: 3
|
vppifaceid: 3
|
||||||
vppbridgeid: 4242
|
vppbridgeid: 4242
|
||||||
macaddrprefix: AA:BB:CC:DD:EE
|
macaddrprefix: AA:BB:CC:DD:EE
|
||||||
mtu: 1400
|
mtu: 1404
|
||||||
recvaddr: 127.0.0.1:4003
|
recvaddr: 127.0.0.1:4003
|
||||||
sendaddr: 127.0.0.1:5003
|
sendaddr: 127.0.0.1:5003
|
||||||
l2headermode: kbdbg
|
l2headermode: kbdbg
|
||||||
nodeid: 3
|
nodeid: 3
|
||||||
nodename: Node03
|
nodename: Node03
|
||||||
|
defaultttl: 200
|
||||||
privkey: gJy35nbsd8FuuxyWHjsefN+U+oM7RkuIB1EanNLSVHg=
|
privkey: gJy35nbsd8FuuxyWHjsefN+U+oM7RkuIB1EanNLSVHg=
|
||||||
listenport: 3003
|
listenport: 3003
|
||||||
loglevel:
|
loglevel:
|
||||||
|
@ -4,12 +4,13 @@ interface:
|
|||||||
vppifaceid: 4
|
vppifaceid: 4
|
||||||
vppbridgeid: 4242
|
vppbridgeid: 4242
|
||||||
macaddrprefix: AA:BB:CC:DD:EE
|
macaddrprefix: AA:BB:CC:DD:EE
|
||||||
mtu: 1400
|
mtu: 1404
|
||||||
recvaddr: 127.0.0.1:4004
|
recvaddr: 127.0.0.1:4004
|
||||||
sendaddr: 127.0.0.1:5004
|
sendaddr: 127.0.0.1:5004
|
||||||
l2headermode: kbdbg
|
l2headermode: kbdbg
|
||||||
nodeid: 4
|
nodeid: 4
|
||||||
nodename: Node04
|
nodename: Node04
|
||||||
|
defaultttl: 200
|
||||||
privkey: wAdLgCk0SHiO11/aUf9944focD1BUCH5b6Pe+cRHHXQ=
|
privkey: wAdLgCk0SHiO11/aUf9944focD1BUCH5b6Pe+cRHHXQ=
|
||||||
listenport: 3004
|
listenport: 3004
|
||||||
loglevel:
|
loglevel:
|
||||||
|
@ -4,12 +4,13 @@ interface:
|
|||||||
vppifaceid: 5
|
vppifaceid: 5
|
||||||
vppbridgeid: 4242
|
vppbridgeid: 4242
|
||||||
macaddrprefix: AA:BB:CC:DD:EE
|
macaddrprefix: AA:BB:CC:DD:EE
|
||||||
mtu: 1400
|
mtu: 1404
|
||||||
recvaddr: 127.0.0.1:4005
|
recvaddr: 127.0.0.1:4005
|
||||||
sendaddr: 127.0.0.1:5005
|
sendaddr: 127.0.0.1:5005
|
||||||
l2headermode: kbdbg
|
l2headermode: kbdbg
|
||||||
nodeid: 5
|
nodeid: 5
|
||||||
nodename: Node05
|
nodename: Node05
|
||||||
|
defaultttl: 200
|
||||||
privkey: gLmzeCbmN/hjiE+ehNXL9IxuG9hhWIYv2s16/DOW6FE=
|
privkey: gLmzeCbmN/hjiE+ehNXL9IxuG9hhWIYv2s16/DOW6FE=
|
||||||
listenport: 3005
|
listenport: 3005
|
||||||
loglevel:
|
loglevel:
|
||||||
|
@ -4,12 +4,13 @@ interface:
|
|||||||
vppifaceid: 6
|
vppifaceid: 6
|
||||||
vppbridgeid: 4242
|
vppbridgeid: 4242
|
||||||
macaddrprefix: AA:BB:CC:DD:EE
|
macaddrprefix: AA:BB:CC:DD:EE
|
||||||
mtu: 1400
|
mtu: 1404
|
||||||
recvaddr: 127.0.0.1:4006
|
recvaddr: 127.0.0.1:4006
|
||||||
sendaddr: 127.0.0.1:5006
|
sendaddr: 127.0.0.1:5006
|
||||||
l2headermode: kbdbg
|
l2headermode: kbdbg
|
||||||
nodeid: 6
|
nodeid: 6
|
||||||
nodename: Node06
|
nodename: Node06
|
||||||
|
defaultttl: 200
|
||||||
privkey: IIX5F6oWZUS2dlhxWFJ7TxdJtDCr5jzeuhxUB6YM7Us=
|
privkey: IIX5F6oWZUS2dlhxWFJ7TxdJtDCr5jzeuhxUB6YM7Us=
|
||||||
listenport: 3006
|
listenport: 3006
|
||||||
loglevel:
|
loglevel:
|
||||||
|
@ -4,12 +4,13 @@ interface:
|
|||||||
vppifaceid: 1
|
vppifaceid: 1
|
||||||
vppbridgeid: 4242
|
vppbridgeid: 4242
|
||||||
macaddrprefix: AA:BB:CC:DD:EE
|
macaddrprefix: AA:BB:CC:DD:EE
|
||||||
mtu: 1400
|
mtu: 1404
|
||||||
recvaddr: 127.0.0.1:4001
|
recvaddr: 127.0.0.1:4001
|
||||||
sendaddr: 127.0.0.1:5001
|
sendaddr: 127.0.0.1:5001
|
||||||
l2headermode: kbdbg
|
l2headermode: kbdbg
|
||||||
nodeid: 1
|
nodeid: 1
|
||||||
nodename: Node01
|
nodename: Node01
|
||||||
|
defaultttl: 200
|
||||||
privkey: aABzjKhWdkFfQ29ZuijtMp1h1TNJe66SDCwvfmvQznw=
|
privkey: aABzjKhWdkFfQ29ZuijtMp1h1TNJe66SDCwvfmvQznw=
|
||||||
listenport: 3001
|
listenport: 3001
|
||||||
loglevel:
|
loglevel:
|
||||||
|
@ -4,12 +4,13 @@ interface:
|
|||||||
vppifaceid: 2
|
vppifaceid: 2
|
||||||
vppbridgeid: 4242
|
vppbridgeid: 4242
|
||||||
macaddrprefix: AA:BB:CC:DD:EE
|
macaddrprefix: AA:BB:CC:DD:EE
|
||||||
mtu: 1400
|
mtu: 1404
|
||||||
recvaddr: 127.0.0.1:4002
|
recvaddr: 127.0.0.1:4002
|
||||||
sendaddr: 127.0.0.1:5002
|
sendaddr: 127.0.0.1:5002
|
||||||
l2headermode: kbdbg
|
l2headermode: kbdbg
|
||||||
nodeid: 2
|
nodeid: 2
|
||||||
nodename: Node02
|
nodename: Node02
|
||||||
|
defaultttl: 200
|
||||||
privkey: UNZMzPX5fG/8yGC8edVj/ksF9N6ARRqdq7fqE/PD7ls=
|
privkey: UNZMzPX5fG/8yGC8edVj/ksF9N6ARRqdq7fqE/PD7ls=
|
||||||
listenport: 3002
|
listenport: 3002
|
||||||
loglevel:
|
loglevel:
|
||||||
|
@ -4,12 +4,13 @@ interface:
|
|||||||
vppifaceid: 3
|
vppifaceid: 3
|
||||||
vppbridgeid: 4242
|
vppbridgeid: 4242
|
||||||
macaddrprefix: AA:BB:CC:DD:EE
|
macaddrprefix: AA:BB:CC:DD:EE
|
||||||
mtu: 1400
|
mtu: 1404
|
||||||
recvaddr: 127.0.0.1:4003
|
recvaddr: 127.0.0.1:4003
|
||||||
sendaddr: 127.0.0.1:5003
|
sendaddr: 127.0.0.1:5003
|
||||||
l2headermode: kbdbg
|
l2headermode: kbdbg
|
||||||
nodeid: 3
|
nodeid: 3
|
||||||
nodename: Node03
|
nodename: Node03
|
||||||
|
defaultttl: 200
|
||||||
privkey: gJy35nbsd8FuuxyWHjsefN+U+oM7RkuIB1EanNLSVHg=
|
privkey: gJy35nbsd8FuuxyWHjsefN+U+oM7RkuIB1EanNLSVHg=
|
||||||
listenport: 3003
|
listenport: 3003
|
||||||
loglevel:
|
loglevel:
|
||||||
|
@ -4,12 +4,13 @@ interface:
|
|||||||
vppifaceid: 4
|
vppifaceid: 4
|
||||||
vppbridgeid: 4242
|
vppbridgeid: 4242
|
||||||
macaddrprefix: AA:BB:CC:DD:EE
|
macaddrprefix: AA:BB:CC:DD:EE
|
||||||
mtu: 1400
|
mtu: 1404
|
||||||
recvaddr: 127.0.0.1:4004
|
recvaddr: 127.0.0.1:4004
|
||||||
sendaddr: 127.0.0.1:5004
|
sendaddr: 127.0.0.1:5004
|
||||||
l2headermode: kbdbg
|
l2headermode: kbdbg
|
||||||
nodeid: 4
|
nodeid: 4
|
||||||
nodename: Node04
|
nodename: Node04
|
||||||
|
defaultttl: 200
|
||||||
privkey: wAdLgCk0SHiO11/aUf9944focD1BUCH5b6Pe+cRHHXQ=
|
privkey: wAdLgCk0SHiO11/aUf9944focD1BUCH5b6Pe+cRHHXQ=
|
||||||
listenport: 3004
|
listenport: 3004
|
||||||
loglevel:
|
loglevel:
|
||||||
|
@ -4,12 +4,13 @@ interface:
|
|||||||
vppifaceid: 5
|
vppifaceid: 5
|
||||||
vppbridgeid: 4242
|
vppbridgeid: 4242
|
||||||
macaddrprefix: AA:BB:CC:DD:EE
|
macaddrprefix: AA:BB:CC:DD:EE
|
||||||
mtu: 1400
|
mtu: 1404
|
||||||
recvaddr: 127.0.0.1:4005
|
recvaddr: 127.0.0.1:4005
|
||||||
sendaddr: 127.0.0.1:5005
|
sendaddr: 127.0.0.1:5005
|
||||||
l2headermode: kbdbg
|
l2headermode: kbdbg
|
||||||
nodeid: 5
|
nodeid: 5
|
||||||
nodename: Node05
|
nodename: Node05
|
||||||
|
defaultttl: 200
|
||||||
privkey: gLmzeCbmN/hjiE+ehNXL9IxuG9hhWIYv2s16/DOW6FE=
|
privkey: gLmzeCbmN/hjiE+ehNXL9IxuG9hhWIYv2s16/DOW6FE=
|
||||||
listenport: 3005
|
listenport: 3005
|
||||||
loglevel:
|
loglevel:
|
||||||
|
@ -4,12 +4,13 @@ interface:
|
|||||||
vppifaceid: 6
|
vppifaceid: 6
|
||||||
vppbridgeid: 4242
|
vppbridgeid: 4242
|
||||||
macaddrprefix: AA:BB:CC:DD:EE
|
macaddrprefix: AA:BB:CC:DD:EE
|
||||||
mtu: 1400
|
mtu: 1404
|
||||||
recvaddr: 127.0.0.1:4006
|
recvaddr: 127.0.0.1:4006
|
||||||
sendaddr: 127.0.0.1:5006
|
sendaddr: 127.0.0.1:5006
|
||||||
l2headermode: kbdbg
|
l2headermode: kbdbg
|
||||||
nodeid: 6
|
nodeid: 6
|
||||||
nodename: Node06
|
nodename: Node06
|
||||||
|
defaultttl: 200
|
||||||
privkey: IIX5F6oWZUS2dlhxWFJ7TxdJtDCr5jzeuhxUB6YM7Us=
|
privkey: IIX5F6oWZUS2dlhxWFJ7TxdJtDCr5jzeuhxUB6YM7Us=
|
||||||
listenport: 3006
|
listenport: 3006
|
||||||
loglevel:
|
loglevel:
|
||||||
|
@ -4,12 +4,13 @@ interface:
|
|||||||
vppifaceid: 1
|
vppifaceid: 1
|
||||||
vppbridgeid: 4242
|
vppbridgeid: 4242
|
||||||
macaddrprefix: AA:BB:CC:DD:EE
|
macaddrprefix: AA:BB:CC:DD:EE
|
||||||
mtu: 1400
|
mtu: 1404
|
||||||
recvaddr: 127.0.0.1:4001
|
recvaddr: 127.0.0.1:4001
|
||||||
sendaddr: 127.0.0.1:5001
|
sendaddr: 127.0.0.1:5001
|
||||||
l2headermode: kbdbg
|
l2headermode: kbdbg
|
||||||
nodeid: 1
|
nodeid: 1
|
||||||
nodename: Node01
|
nodename: Node01
|
||||||
|
defaultttl: 200
|
||||||
privkey: 6GyDagZKhbm5WNqMiRHhkf43RlbMJ34IieTlIuvfJ1M=
|
privkey: 6GyDagZKhbm5WNqMiRHhkf43RlbMJ34IieTlIuvfJ1M=
|
||||||
listenport: 3001
|
listenport: 3001
|
||||||
loglevel:
|
loglevel:
|
||||||
|
@ -4,12 +4,13 @@ interface:
|
|||||||
vppifaceid: 2
|
vppifaceid: 2
|
||||||
vppbridgeid: 4242
|
vppbridgeid: 4242
|
||||||
macaddrprefix: AA:BB:CC:DD:EE
|
macaddrprefix: AA:BB:CC:DD:EE
|
||||||
mtu: 1400
|
mtu: 1404
|
||||||
recvaddr: 127.0.0.1:4002
|
recvaddr: 127.0.0.1:4002
|
||||||
sendaddr: 127.0.0.1:5002
|
sendaddr: 127.0.0.1:5002
|
||||||
l2headermode: kbdbg
|
l2headermode: kbdbg
|
||||||
nodeid: 2
|
nodeid: 2
|
||||||
nodename: Node02
|
nodename: Node02
|
||||||
|
defaultttl: 200
|
||||||
privkey: OH8BsVUU2Rqzeu9B2J5GPG8PUmxWfX8uVvNFZKhVF3o=
|
privkey: OH8BsVUU2Rqzeu9B2J5GPG8PUmxWfX8uVvNFZKhVF3o=
|
||||||
listenport: 3002
|
listenport: 3002
|
||||||
loglevel:
|
loglevel:
|
||||||
|
@ -16,10 +16,10 @@ graphrecalculatesetting:
|
|||||||
recalculatecooldown: 5
|
recalculatecooldown: 5
|
||||||
peers:
|
peers:
|
||||||
- nodeid: 1
|
- nodeid: 1
|
||||||
|
name: "Node_01"
|
||||||
pubkey: ZqzLVSbXzjppERslwbf2QziWruW3V/UIx9oqwU8Fn3I=
|
pubkey: ZqzLVSbXzjppERslwbf2QziWruW3V/UIx9oqwU8Fn3I=
|
||||||
endpoint: 127.0.0.1:3001
|
pskey: ""
|
||||||
static: true
|
|
||||||
- nodeid: 2
|
- nodeid: 2
|
||||||
|
name: "Node_02"
|
||||||
pubkey: dHeWQtlTPQGy87WdbUARS4CtwVaR2y7IQ1qcX4GKSXk=
|
pubkey: dHeWQtlTPQGy87WdbUARS4CtwVaR2y7IQ1qcX4GKSXk=
|
||||||
endpoint: 127.0.0.1:3002
|
pskey: ""
|
||||||
static: true
|
|
62
main_edge.go
62
main_edge.go
@ -138,23 +138,23 @@ func Edge(configPath string, useUAPI bool, printExample bool) (err error) {
|
|||||||
printExampleEdgeConf()
|
printExampleEdgeConf()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
var tconfig config.EdgeConfig
|
var econfig config.EdgeConfig
|
||||||
//printExampleConf()
|
//printExampleConf()
|
||||||
//return
|
//return
|
||||||
|
|
||||||
err = readYaml(configPath, &tconfig)
|
err = readYaml(configPath, &econfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error read config: %s :", configPath)
|
fmt.Printf("Error read config: %s :", configPath)
|
||||||
fmt.Print(err)
|
fmt.Print(err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeName := tconfig.NodeName
|
NodeName := econfig.NodeName
|
||||||
if len(NodeName) > 32 {
|
if len(NodeName) > 32 {
|
||||||
return errors.New("Node name can't longer than 32 :" + NodeName)
|
return errors.New("Node name can't longer than 32 :" + NodeName)
|
||||||
}
|
}
|
||||||
var logLevel int
|
var logLevel int
|
||||||
switch tconfig.LogLevel.LogLevel {
|
switch econfig.LogLevel.LogLevel {
|
||||||
case "verbose", "debug":
|
case "verbose", "debug":
|
||||||
logLevel = device.LogLevelVerbose
|
logLevel = device.LogLevelVerbose
|
||||||
case "error":
|
case "error":
|
||||||
@ -177,45 +177,49 @@ func Edge(configPath string, useUAPI bool, printExample bool) (err error) {
|
|||||||
|
|
||||||
var thetap tap.Device
|
var thetap tap.Device
|
||||||
// open TUN device (or use supplied fd)
|
// open TUN device (or use supplied fd)
|
||||||
switch tconfig.Interface.Itype {
|
switch econfig.Interface.Itype {
|
||||||
case "dummy":
|
case "dummy":
|
||||||
thetap, err = tap.CreateDummyTAP()
|
thetap, err = tap.CreateDummyTAP()
|
||||||
case "stdio":
|
case "stdio":
|
||||||
thetap, err = tap.CreateStdIOTAP(tconfig.Interface,tconfig.NodeID)
|
thetap, err = tap.CreateStdIOTAP(econfig.Interface, econfig.NodeID)
|
||||||
case "udpsock":
|
case "udpsock":
|
||||||
lis, _ := net.ResolveUDPAddr("udp", tconfig.Interface.RecvAddr)
|
lis, _ := net.ResolveUDPAddr("udp", econfig.Interface.RecvAddr)
|
||||||
sen, _ := net.ResolveUDPAddr("udp", tconfig.Interface.SendAddr)
|
sen, _ := net.ResolveUDPAddr("udp", econfig.Interface.SendAddr)
|
||||||
thetap, err = tap.CreateUDPSockTAP(tconfig.Interface,tconfig.NodeID, lis, sen)
|
thetap, err = tap.CreateUDPSockTAP(econfig.Interface, econfig.NodeID, lis, sen)
|
||||||
case "vpp":
|
case "vpp":
|
||||||
thetap, err = tap.CreateVppTAP(tconfig.Interface,tconfig.NodeID,tconfig.LogLevel.LogLevel)
|
thetap, err = tap.CreateVppTAP(econfig.Interface, econfig.NodeID, econfig.LogLevel.LogLevel)
|
||||||
case "tap":
|
case "tap":
|
||||||
thetap, err = tap.CreateTAP(tconfig.Interface,tconfig.NodeID)
|
thetap, err = tap.CreateTAP(econfig.Interface, econfig.NodeID)
|
||||||
default:
|
default:
|
||||||
return errors.New("Unknow interface type:" + tconfig.Interface.Itype)
|
return errors.New("Unknow interface type:" + econfig.Interface.Itype)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Errorf("Failed to create TAP device: %v", err)
|
logger.Errorf("Failed to create TAP device: %v", err)
|
||||||
os.Exit(ExitSetupFailed)
|
os.Exit(ExitSetupFailed)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if econfig.DefaultTTL <= 0 {
|
||||||
|
return errors.New("DefaultTTL must > 0")
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////
|
////////////////////////////////////////////////////
|
||||||
// Config
|
// Config
|
||||||
if tconfig.DynamicRoute.P2P.UseP2P == false && tconfig.DynamicRoute.SuperNode.UseSuperNode == false {
|
if econfig.DynamicRoute.P2P.UseP2P == false && econfig.DynamicRoute.SuperNode.UseSuperNode == false {
|
||||||
tconfig.LogLevel.LogNTP = false // NTP in static mode is useless
|
econfig.LogLevel.LogNTP = false // NTP in static mode is useless
|
||||||
}
|
}
|
||||||
graph := path.NewGraph(3, false, tconfig.DynamicRoute.P2P.GraphRecalculateSetting, tconfig.DynamicRoute.NTPconfig, tconfig.LogLevel.LogNTP)
|
graph := path.NewGraph(3, false, econfig.DynamicRoute.P2P.GraphRecalculateSetting, econfig.DynamicRoute.NTPconfig, econfig.LogLevel.LogNTP)
|
||||||
graph.SetNHTable(tconfig.NextHopTable, [32]byte{})
|
graph.SetNHTable(econfig.NextHopTable, [32]byte{})
|
||||||
|
|
||||||
the_device := device.NewDevice(thetap, tconfig.NodeID, conn.NewDefaultBind(), logger, graph, false, configPath, &tconfig, nil, nil)
|
the_device := device.NewDevice(thetap, econfig.NodeID, conn.NewDefaultBind(), logger, graph, false, configPath, &econfig, nil, nil,Version)
|
||||||
defer the_device.Close()
|
defer the_device.Close()
|
||||||
var sk [32]byte
|
var sk [32]byte
|
||||||
sk_slice, _ := base64.StdEncoding.DecodeString(tconfig.PrivKey)
|
sk_slice, _ := base64.StdEncoding.DecodeString(econfig.PrivKey)
|
||||||
copy(sk[:], sk_slice)
|
copy(sk[:], sk_slice)
|
||||||
the_device.SetPrivateKey(sk)
|
the_device.SetPrivateKey(sk)
|
||||||
the_device.IpcSet("fwmark=0\n")
|
the_device.IpcSet("fwmark=0\n")
|
||||||
the_device.IpcSet("listen_port=" + strconv.Itoa(tconfig.ListenPort) + "\n")
|
the_device.IpcSet("listen_port=" + strconv.Itoa(econfig.ListenPort) + "\n")
|
||||||
the_device.IpcSet("replace_peers=true\n")
|
the_device.IpcSet("replace_peers=true\n")
|
||||||
for _, peerconf := range tconfig.Peers {
|
for _, peerconf := range econfig.Peers {
|
||||||
sk_slice, _ = base64.StdEncoding.DecodeString(peerconf.PubKey)
|
sk_slice, _ = base64.StdEncoding.DecodeString(peerconf.PubKey)
|
||||||
copy(sk[:], sk_slice)
|
copy(sk[:], sk_slice)
|
||||||
if peerconf.NodeID >= config.SuperNodeMessage {
|
if peerconf.NodeID >= config.SuperNodeMessage {
|
||||||
@ -235,11 +239,11 @@ func Edge(configPath string, useUAPI bool, printExample bool) (err error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if tconfig.DynamicRoute.SuperNode.UseSuperNode {
|
if econfig.DynamicRoute.SuperNode.UseSuperNode {
|
||||||
if tconfig.DynamicRoute.SuperNode.ConnURLV4 != "" {
|
if econfig.DynamicRoute.SuperNode.ConnURLV4 != "" {
|
||||||
sk_slice, _ = base64.StdEncoding.DecodeString(tconfig.DynamicRoute.SuperNode.PubKeyV4)
|
sk_slice, _ = base64.StdEncoding.DecodeString(econfig.DynamicRoute.SuperNode.PubKeyV4)
|
||||||
copy(sk[:], sk_slice)
|
copy(sk[:], sk_slice)
|
||||||
endpoint, err := the_device.Bind().ParseEndpoint(tconfig.DynamicRoute.SuperNode.ConnURLV4)
|
endpoint, err := the_device.Bind().ParseEndpoint(econfig.DynamicRoute.SuperNode.ConnURLV4)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -248,13 +252,13 @@ func Edge(configPath string, useUAPI bool, printExample bool) (err error) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
peer.StaticConn = false
|
peer.StaticConn = false
|
||||||
peer.ConnURL = tconfig.DynamicRoute.SuperNode.ConnURLV4
|
peer.ConnURL = econfig.DynamicRoute.SuperNode.ConnURLV4
|
||||||
peer.SetEndpointFromPacket(endpoint)
|
peer.SetEndpointFromPacket(endpoint)
|
||||||
}
|
}
|
||||||
if tconfig.DynamicRoute.SuperNode.ConnURLV6 != "" {
|
if econfig.DynamicRoute.SuperNode.ConnURLV6 != "" {
|
||||||
sk_slice, _ = base64.StdEncoding.DecodeString(tconfig.DynamicRoute.SuperNode.PubKeyV6)
|
sk_slice, _ = base64.StdEncoding.DecodeString(econfig.DynamicRoute.SuperNode.PubKeyV6)
|
||||||
copy(sk[:], sk_slice)
|
copy(sk[:], sk_slice)
|
||||||
endpoint, err := the_device.Bind().ParseEndpoint(tconfig.DynamicRoute.SuperNode.ConnURLV6)
|
endpoint, err := the_device.Bind().ParseEndpoint(econfig.DynamicRoute.SuperNode.ConnURLV6)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -263,7 +267,7 @@ func Edge(configPath string, useUAPI bool, printExample bool) (err error) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
peer.StaticConn = false
|
peer.StaticConn = false
|
||||||
peer.ConnURL = tconfig.DynamicRoute.SuperNode.ConnURLV6
|
peer.ConnURL = econfig.DynamicRoute.SuperNode.ConnURLV6
|
||||||
peer.SetEndpointFromPacket(endpoint)
|
peer.SetEndpointFromPacket(endpoint)
|
||||||
}
|
}
|
||||||
the_device.Event_Supernode_OK <- struct{}{}
|
the_device.Event_Supernode_OK <- struct{}{}
|
||||||
|
@ -43,12 +43,12 @@ func printExampleSuperConf() {
|
|||||||
LogControl: true,
|
LogControl: true,
|
||||||
},
|
},
|
||||||
RePushConfigInterval: 30,
|
RePushConfigInterval: 30,
|
||||||
Peers: []config.PeerInfo{
|
Peers: []config.SuperPeerInfo{
|
||||||
{
|
{
|
||||||
NodeID: 2,
|
NodeID: 2,
|
||||||
PubKey: "NuYJ/3Ght+C4HovFq5Te/BrIazo6zwDJ8Bdu4rQCz0o=",
|
Name: "Node02",
|
||||||
EndPoint: "127.0.0.1:3002",
|
PubKey: "NuYJ/3Ght+C4HovFq5Te/BrIazo6zwDJ8Bdu4rQCz0o=",
|
||||||
Static: true,
|
PSKey: "NuYJ/3Ght+C4HovFq5Te/BrIazo6zwDJ8Bdu4rQCz0o=",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
GraphRecalculateSetting: config.GraphRecalculateSetting{
|
GraphRecalculateSetting: config.GraphRecalculateSetting{
|
||||||
@ -116,8 +116,8 @@ func Super(configPath string, useUAPI bool, printExample bool) (err error) {
|
|||||||
thetap4, _ := tap.CreateDummyTAP()
|
thetap4, _ := tap.CreateDummyTAP()
|
||||||
thetap6, _ := tap.CreateDummyTAP()
|
thetap6, _ := tap.CreateDummyTAP()
|
||||||
http_graph = path.NewGraph(3, true, sconfig.GraphRecalculateSetting, config.NTPinfo{}, sconfig.LogLevel.LogNTP)
|
http_graph = path.NewGraph(3, true, sconfig.GraphRecalculateSetting, config.NTPinfo{}, sconfig.LogLevel.LogNTP)
|
||||||
http_device4 = device.NewDevice(thetap4, config.SuperNodeMessage, conn.NewCustomBind(true, false), logger4, http_graph, true, configPath, nil, &sconfig, &super_chains)
|
http_device4 = device.NewDevice(thetap4, config.SuperNodeMessage, conn.NewCustomBind(true, false), logger4, http_graph, true, configPath, nil, &sconfig, &super_chains, Version)
|
||||||
http_device6 = device.NewDevice(thetap6, config.SuperNodeMessage, conn.NewCustomBind(false, true), logger6, http_graph, true, configPath, nil, &sconfig, &super_chains)
|
http_device6 = device.NewDevice(thetap6, config.SuperNodeMessage, conn.NewCustomBind(false, true), logger6, http_graph, true, configPath, nil, &sconfig, &super_chains, Version)
|
||||||
defer http_device4.Close()
|
defer http_device4.Close()
|
||||||
defer http_device6.Close()
|
defer http_device6.Close()
|
||||||
var sk [32]byte
|
var sk [32]byte
|
||||||
@ -143,6 +143,7 @@ func Super(configPath string, useUAPI bool, printExample bool) (err error) {
|
|||||||
http_device6.IpcSet("replace_peers=true\n")
|
http_device6.IpcSet("replace_peers=true\n")
|
||||||
|
|
||||||
for _, peerconf := range sconfig.Peers {
|
for _, peerconf := range sconfig.Peers {
|
||||||
|
http_peerinfos.Store(peerconf.NodeID, peerconf.Name)
|
||||||
var pk device.NoisePublicKey
|
var pk device.NoisePublicKey
|
||||||
|
|
||||||
pk_slice, err := base64.StdEncoding.DecodeString(peerconf.PubKey)
|
pk_slice, err := base64.StdEncoding.DecodeString(peerconf.PubKey)
|
||||||
@ -166,14 +167,12 @@ func Super(configPath string, useUAPI bool, printExample bool) (err error) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
peer4.StaticConn = true
|
peer4.StaticConn = true
|
||||||
peer4.ConnURL = peerconf.EndPoint
|
|
||||||
peer6, err := http_device6.NewPeer(pk, peerconf.NodeID)
|
peer6, err := http_device6.NewPeer(pk, peerconf.NodeID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error create peer id %v\n", peerconf.NodeID)
|
fmt.Printf("Error create peer id %v\n", peerconf.NodeID)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
peer6.StaticConn = true
|
peer6.StaticConn = true
|
||||||
peer6.ConnURL = peerconf.EndPoint
|
|
||||||
if peerconf.PSKey != "" {
|
if peerconf.PSKey != "" {
|
||||||
var psk device.NoisePresharedKey
|
var psk device.NoisePresharedKey
|
||||||
psk_slice, err := base64.StdEncoding.DecodeString(peerconf.PSKey)
|
psk_slice, err := base64.StdEncoding.DecodeString(peerconf.PSKey)
|
||||||
@ -225,7 +224,6 @@ func Event_server_event_hendler(graph *path.IG, events path.SUPER_Events) {
|
|||||||
case reg_msg := <-events.Event_server_register:
|
case reg_msg := <-events.Event_server_register:
|
||||||
copy(http_PeerState[http_PeerID2Map[reg_msg.Node_id]].NhTableState[:], reg_msg.NhStateHash[:])
|
copy(http_PeerState[http_PeerID2Map[reg_msg.Node_id]].NhTableState[:], reg_msg.NhStateHash[:])
|
||||||
copy(http_PeerState[http_PeerID2Map[reg_msg.Node_id]].PeerInfoState[:], reg_msg.PeerStateHash[:])
|
copy(http_PeerState[http_PeerID2Map[reg_msg.Node_id]].PeerInfoState[:], reg_msg.PeerStateHash[:])
|
||||||
http_peerinfos.Store(reg_msg.Node_id, reg_msg.Name)
|
|
||||||
PubKey := http_PeerID2Map[reg_msg.Node_id]
|
PubKey := http_PeerID2Map[reg_msg.Node_id]
|
||||||
if peer := http_device4.LookupPeerByStr(PubKey); peer != nil {
|
if peer := http_device4.LookupPeerByStr(PubKey); peer != nil {
|
||||||
if connstr := peer.GetEndpointDstStr(); connstr != "" {
|
if connstr := peer.GetEndpointDstStr(); connstr != "" {
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
"github.com/KusakabeSi/EtherGuardVPN/config"
|
"github.com/KusakabeSi/EtherGuardVPN/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
const EgHeaderLen = 16
|
const EgHeaderLen = 8
|
||||||
|
|
||||||
type EgHeader struct {
|
type EgHeader struct {
|
||||||
buf []byte
|
buf []byte
|
||||||
@ -21,13 +21,12 @@ const (
|
|||||||
|
|
||||||
UpdatePeer //Comes from server
|
UpdatePeer //Comes from server
|
||||||
UpdateNhTable
|
UpdateNhTable
|
||||||
|
UpdateError
|
||||||
|
|
||||||
PingPacket //Comes from other peer
|
PingPacket //Comes from other peer
|
||||||
PongPacket //Send to everyone, include server
|
PongPacket //Send to everyone, include server
|
||||||
QueryPeer
|
QueryPeer
|
||||||
BoardcastPeer
|
BoardcastPeer
|
||||||
|
|
||||||
UpdateError
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewEgHeader(pac []byte) (e EgHeader, err error) {
|
func NewEgHeader(pac []byte) (e EgHeader, err error) {
|
||||||
@ -40,44 +39,37 @@ func NewEgHeader(pac []byte) (e EgHeader, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e EgHeader) GetDst() config.Vertex {
|
func (e EgHeader) GetDst() config.Vertex {
|
||||||
return config.Vertex(binary.BigEndian.Uint32(e.buf[0:4]))
|
return config.Vertex(binary.BigEndian.Uint16(e.buf[0:2]))
|
||||||
}
|
}
|
||||||
func (e EgHeader) SetDst(node_ID config.Vertex) {
|
func (e EgHeader) SetDst(node_ID config.Vertex) {
|
||||||
binary.BigEndian.PutUint32(e.buf[0:4], uint32(node_ID))
|
binary.BigEndian.PutUint16(e.buf[0:2], uint16(node_ID))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e EgHeader) GetSrc() config.Vertex {
|
func (e EgHeader) GetSrc() config.Vertex {
|
||||||
return config.Vertex(binary.BigEndian.Uint32(e.buf[4:8]))
|
return config.Vertex(binary.BigEndian.Uint16(e.buf[2:4]))
|
||||||
}
|
}
|
||||||
func (e EgHeader) SetSrc(node_ID config.Vertex) {
|
func (e EgHeader) SetSrc(node_ID config.Vertex) {
|
||||||
binary.BigEndian.PutUint32(e.buf[4:8], uint32(node_ID))
|
binary.BigEndian.PutUint16(e.buf[2:4], uint16(node_ID))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e EgHeader) GetTTL() uint8 {
|
func (e EgHeader) GetTTL() uint8 {
|
||||||
return e.buf[8]
|
return e.buf[4]
|
||||||
}
|
}
|
||||||
func (e EgHeader) SetTTL(ttl uint8) {
|
func (e EgHeader) SetTTL(ttl uint8) {
|
||||||
|
|
||||||
e.buf[8] = ttl
|
e.buf[4] = ttl
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e EgHeader) GetUsage() Usage {
|
func (e EgHeader) GetUsage() Usage {
|
||||||
return Usage(e.buf[9])
|
return Usage(e.buf[5])
|
||||||
}
|
}
|
||||||
func (e EgHeader) SetUsage(usage Usage) {
|
func (e EgHeader) SetUsage(usage Usage) {
|
||||||
e.buf[9] = uint8(usage)
|
e.buf[5] = uint8(usage)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e EgHeader) GetPacketLength() uint16 {
|
func (e EgHeader) GetPacketLength() uint16 {
|
||||||
return binary.BigEndian.Uint16(e.buf[10:12])
|
return binary.BigEndian.Uint16(e.buf[6:8])
|
||||||
}
|
}
|
||||||
func (e EgHeader) SetPacketLength(length uint16) {
|
func (e EgHeader) SetPacketLength(length uint16) {
|
||||||
binary.BigEndian.PutUint16(e.buf[10:12], length)
|
binary.BigEndian.PutUint16(e.buf[6:8], length)
|
||||||
}
|
|
||||||
|
|
||||||
func (e EgHeader) GetMessageID() uint32 {
|
|
||||||
return binary.BigEndian.Uint32(e.buf[12:16])
|
|
||||||
}
|
|
||||||
func (e EgHeader) SetMessageID(MessageID uint32) {
|
|
||||||
binary.BigEndian.PutUint32(e.buf[12:16], MessageID)
|
|
||||||
}
|
}
|
||||||
|
@ -24,11 +24,11 @@ type RegisterMsg struct {
|
|||||||
Node_id config.Vertex
|
Node_id config.Vertex
|
||||||
PeerStateHash [32]byte
|
PeerStateHash [32]byte
|
||||||
NhStateHash [32]byte
|
NhStateHash [32]byte
|
||||||
Name string
|
Version string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *RegisterMsg) ToString() string {
|
func (c *RegisterMsg) ToString() string {
|
||||||
return "RegisterMsg Node_id:" + c.Node_id.ToString() + " Name:" + c.Name + " PeerHash:" + base64.StdEncoding.EncodeToString(c.PeerStateHash[:]) + " NhHash:" + base64.StdEncoding.EncodeToString(c.NhStateHash[:])
|
return "RegisterMsg Node_id:" + c.Node_id.ToString() + " Version:" + c.Version + " PeerHash:" + base64.StdEncoding.EncodeToString(c.PeerStateHash[:]) + " NhHash:" + base64.StdEncoding.EncodeToString(c.NhStateHash[:])
|
||||||
}
|
}
|
||||||
|
|
||||||
func ParseRegisterMsg(bin []byte) (StructPlace RegisterMsg, err error) {
|
func ParseRegisterMsg(bin []byte) (StructPlace RegisterMsg, err error) {
|
||||||
@ -42,7 +42,8 @@ func ParseRegisterMsg(bin []byte) (StructPlace RegisterMsg, err error) {
|
|||||||
type ErrorAction int
|
type ErrorAction int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Shutdown ErrorAction = iota
|
NoAction ErrorAction = iota
|
||||||
|
Shutdown
|
||||||
Panic
|
Panic
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user