Add a way to record and handle errors

This commit is contained in:
eyedeekay
2025-02-03 17:00:21 -05:00
parent c525371823
commit 0ea3942381
4 changed files with 44 additions and 4 deletions

View File

@ -46,6 +46,13 @@ type TCPClient struct {
i2ptunnel.I2PTunnelStatus
// Channel for shutdown signaling
done chan struct{}
// Error history of the tunnel
Errors []i2ptunnel.I2PTunnelError
}
func (t *TCPClient) recordError(err error) {
t.Errors = append(t.Errors, i2ptunnel.NewError(t, err))
}
// Get the tunnel's I2P address
@ -55,7 +62,10 @@ func (t *TCPClient) Address() string {
// Get the tunnel's error message
func (t *TCPClient) Error() error {
panic("unimplemented")
if len(t.Errors) > 0 {
return t.Errors[len(t.Errors)-1]
}
return nil
}
// Get the tunnel's local host:port

View File

@ -40,6 +40,13 @@ type TCPServer struct {
limitedlistener.LimitedConfig
// Channel for shutdown signaling
done chan struct{}
// Error history of the tunnel
Errors []i2ptunnel.I2PTunnelError
}
func (t *TCPServer) recordError(err error) {
t.Errors = append(t.Errors, i2ptunnel.NewError(t, err))
}
// Get the tunnel's I2P address
@ -49,7 +56,10 @@ func (t *TCPServer) Address() string {
// Get the tunnel's error message
func (t *TCPServer) Error() error {
panic("unimplemented")
if len(t.Errors) > 0 {
return t.Errors[len(t.Errors)-1]
}
return nil
}
// Get the tunnel's local host:port

View File

@ -48,6 +48,13 @@ type UDPClient struct {
i2ptunnel.I2PTunnelStatus
// Channel for shutdown signaling
done chan struct{}
// Error history of the tunnel
Errors []i2ptunnel.I2PTunnelError
}
func (u *UDPClient) recordError(err error) {
u.Errors = append(u.Errors, i2ptunnel.NewError(u, err))
}
// Get the tunnel's I2P address
@ -57,7 +64,10 @@ func (u *UDPClient) Address() string {
// Get the tunnel's error message
func (u *UDPClient) Error() error {
panic("unimplemented")
if len(u.Errors) > 0 {
return u.Errors[len(u.Errors)-1]
}
return nil
}
// Get the tunnel's local host:port

View File

@ -48,6 +48,13 @@ type UDPServer struct {
i2ptunnel.I2PTunnelStatus
// Channel for shutdown signaling
done chan struct{}
// Error history of the tunnel
Errors []i2ptunnel.I2PTunnelError
}
func (u *UDPServer) recordError(err error) {
u.Errors = append(u.Errors, i2ptunnel.NewError(u, err))
}
// Get the tunnel's I2P address
@ -57,7 +64,10 @@ func (u *UDPServer) Address() string {
// Get the tunnel's error message
func (u *UDPServer) Error() error {
panic("unimplemented")
if len(u.Errors) > 0 {
return u.Errors[len(u.Errors)-1]
}
return nil
}
// Get the tunnel's local host:port