0.3.7 - announce packet improvements, cryptgraphy pkg, cleanup

This commit is contained in:
Sudo-Ivan
2025-01-04 18:20:36 -06:00
parent a5b905bbaf
commit 79e1caa815
7 changed files with 137 additions and 94 deletions

View File

@@ -284,3 +284,31 @@ func (i *BaseInterface) updateBandwidthStats(bytes uint64) {
log.Printf("[DEBUG-%d] Interface %s: Updated bandwidth stats - TX bytes: %d, Last TX: %v", DEBUG_LEVEL, i.Name, i.TxBytes, i.lastTx)
}
type InterceptedInterface struct {
Interface
interceptor func([]byte, common.NetworkInterface) error
originalSend func([]byte, string) error
}
// Create constructor for intercepted interface
func NewInterceptedInterface(base Interface, interceptor func([]byte, common.NetworkInterface) error) *InterceptedInterface {
return &InterceptedInterface{
Interface: base,
interceptor: interceptor,
originalSend: base.Send,
}
}
// Implement Send method for intercepted interface
func (i *InterceptedInterface) Send(data []byte, addr string) error {
// Call interceptor if provided
if i.interceptor != nil && len(data) > 0 {
if err := i.interceptor(data, i); err != nil {
log.Printf("[DEBUG-2] Failed to intercept outgoing packet: %v", err)
}
}
// Call original send
return i.originalSend(data, addr)
}