mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-02-26 01:31:26 -05:00
separate addPeer into VPN- and store-add (#18)
This commit is contained in:
parent
cf738bb973
commit
719b6d5f6f
@ -39,6 +39,14 @@ func (c *Core) GetPeers(resourceVersion int) (int, []peer.Peer, error) {
|
|||||||
|
|
||||||
// AddPeer adds a peer to the store and the VPN.
|
// AddPeer adds a peer to the store and the VPN.
|
||||||
func (c *Core) AddPeer(peer peer.Peer) error {
|
func (c *Core) AddPeer(peer peer.Peer) error {
|
||||||
|
if err := c.AddPeerToVPN(peer); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return c.AddPeerToStore(peer)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddPeerToVPN adds a peer to the the VPN.
|
||||||
|
func (c *Core) AddPeerToVPN(peer peer.Peer) error {
|
||||||
publicIP, _, err := net.SplitHostPort(peer.PublicEndpoint)
|
publicIP, _, err := net.SplitHostPort(peer.PublicEndpoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.zaplogger.Info("SplitHostPort", zap.Error(err))
|
c.zaplogger.Info("SplitHostPort", zap.Error(err))
|
||||||
@ -52,12 +60,16 @@ func (c *Core) AddPeer(peer peer.Peer) error {
|
|||||||
}
|
}
|
||||||
if myIP != peer.VPNIP {
|
if myIP != peer.VPNIP {
|
||||||
if err := c.vpn.AddPeer(peer.VPNPubKey, publicIP, peer.VPNIP); err != nil {
|
if err := c.vpn.AddPeer(peer.VPNPubKey, publicIP, peer.VPNIP); err != nil {
|
||||||
c.zaplogger.Error("Failed to add peer to VPN", zap.Error(err), zap.String("public_ip", publicIP), zap.String("vpn_ip", peer.VPNIP))
|
c.zaplogger.Error("failed to add peer to VPN", zap.Error(err), zap.String("peer public_ip", publicIP), zap.String("peer vpn_ip", peer.VPNIP))
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
c.zaplogger.Info("Added peer to VPN", zap.String("public_ip", publicIP), zap.String("vpn_ip", peer.VPNIP))
|
c.zaplogger.Info("added peer to VPN", zap.String("peer public_ip", publicIP), zap.String("peer vpn_ip", peer.VPNIP))
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddPeerToStore adds a peer to the store.
|
||||||
|
func (c *Core) AddPeerToStore(peer peer.Peer) error {
|
||||||
tx, err := c.store.BeginTransaction()
|
tx, err := c.store.BeginTransaction()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -71,8 +83,11 @@ func (c *Core) AddPeer(peer peer.Peer) error {
|
|||||||
if err := txdata.PutPeer(peer); err != nil {
|
if err := txdata.PutPeer(peer); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if err := tx.Commit(); err != nil {
|
||||||
return tx.Commit()
|
return err
|
||||||
|
}
|
||||||
|
c.zaplogger.Info("added peer to store", zap.String("peer public_endpoint", peer.PublicEndpoint), zap.String("peer vpn_ip", peer.VPNIP))
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdatePeers synchronizes the peers known to the store and the vpn with the passed peers.
|
// UpdatePeers synchronizes the peers known to the store and the vpn with the passed peers.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user