mirror of
https://github.com/netbirdio/netbird.git
synced 2026-09-21 14:19:08 +02:00
Create conn mgr
This commit is contained in:
@@ -213,8 +213,8 @@ func (c *KernelConfigurer) GetStats(peerKey string) (WGStats, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c *KernelConfigurer) Transfers() (map[wgtypes.Key]WGStats, error) {
|
||||
stats := make(map[wgtypes.Key]WGStats)
|
||||
func (c *KernelConfigurer) Transfers() (map[string]WGStats, error) {
|
||||
stats := make(map[string]WGStats)
|
||||
wg, err := wgctrl.New()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("wgctl: %w", err)
|
||||
@@ -231,7 +231,7 @@ func (c *KernelConfigurer) Transfers() (map[wgtypes.Key]WGStats, error) {
|
||||
return nil, fmt.Errorf("get device %s: %w", c.deviceName, err)
|
||||
}
|
||||
for _, peer := range wgDevice.Peers {
|
||||
stats[peer.PublicKey] = WGStats{
|
||||
stats[peer.PublicKey.String()] = WGStats{
|
||||
LastHandshake: peer.LastHandshakeTime,
|
||||
TxBytes: peer.TransmitBytes,
|
||||
RxBytes: peer.ReceiveBytes,
|
||||
|
||||
@@ -263,7 +263,7 @@ func (t *WGUSPConfigurer) GetStats(peerKey string) (WGStats, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (t *WGUSPConfigurer) Transfers() (map[wgtypes.Key]WGStats, error) {
|
||||
func (t *WGUSPConfigurer) Transfers() (map[string]WGStats, error) {
|
||||
ipc, err := t.device.IpcGet()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("ipc get: %w", err)
|
||||
@@ -272,10 +272,10 @@ func (t *WGUSPConfigurer) Transfers() (map[wgtypes.Key]WGStats, error) {
|
||||
return parseTransfers(ipc)
|
||||
}
|
||||
|
||||
func parseTransfers(ipc string) (map[wgtypes.Key]WGStats, error) {
|
||||
stats := make(map[wgtypes.Key]WGStats)
|
||||
func parseTransfers(ipc string) (map[string]WGStats, error) {
|
||||
stats := make(map[string]WGStats)
|
||||
var (
|
||||
currentKey wgtypes.Key
|
||||
currentKey string
|
||||
currentStats WGStats
|
||||
hasPeer bool
|
||||
)
|
||||
@@ -291,14 +291,7 @@ func parseTransfers(ipc string) (map[wgtypes.Key]WGStats, error) {
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("decode peerID: %w", err)
|
||||
}
|
||||
b64 := base64.StdEncoding.EncodeToString(h)
|
||||
|
||||
peerKeyParsed, err := wgtypes.ParseKey(b64)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("parse key: %w", err)
|
||||
}
|
||||
|
||||
currentKey = peerKeyParsed
|
||||
currentKey = base64.StdEncoding.EncodeToString(h)
|
||||
currentStats = WGStats{} // Reset stats for the new peer
|
||||
hasPeer = true
|
||||
stats[currentKey] = currentStats
|
||||
|
||||
@@ -17,5 +17,5 @@ type WGConfigurer interface {
|
||||
RemoveAllowedIP(peerKey string, allowedIP string) error
|
||||
Close()
|
||||
GetStats(peerKey string) (configurer.WGStats, error)
|
||||
Transfers() (map[wgtypes.Key]configurer.WGStats, error)
|
||||
Transfers() (map[string]configurer.WGStats, error)
|
||||
}
|
||||
|
||||
@@ -218,7 +218,7 @@ func (w *WGIface) GetStats(peerKey string) (configurer.WGStats, error) {
|
||||
return w.configurer.GetStats(peerKey)
|
||||
}
|
||||
|
||||
func (w *WGIface) Transfers() (map[wgtypes.Key]configurer.WGStats, error) {
|
||||
func (w *WGIface) Transfers() (map[string]configurer.WGStats, error) {
|
||||
return w.configurer.Transfers()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user