added default notice handling interface

This commit is contained in:
2025-02-18 14:44:45 +09:00
parent 81f7bb0c0d
commit 2b3a841299
6 changed files with 286 additions and 174 deletions

View File

@ -61,7 +61,7 @@ func (spc *ServerPeerConn) RunTask(wg *sync.WaitGroup) {
pss = spc.route.Cts.pss
err = pss.Send(MakePeerStartedPacket(spc.route.Id, spc.conn_id, conn_raddr, conn_laddr))
if err != nil {
spc.route.Cts.svr.log.Write(spc.route.Cts.sid, LOG_ERROR,
spc.route.Cts.S.log.Write(spc.route.Cts.sid, LOG_ERROR,
"Failed to send peer_started event(%d,%d,%s,%s) to client - %s",
spc.route.Id, spc.conn_id, conn_raddr, conn_laddr, err.Error())
goto done_without_stop
@ -69,7 +69,7 @@ func (spc *ServerPeerConn) RunTask(wg *sync.WaitGroup) {
// set up a timer to set waiting duration until the connection is
// actually established on the client side and it's informed...
waitctx, cancel_wait = context.WithTimeout(spc.route.Cts.svr.ctx, 5 * time.Second) // TODO: make this configurable
waitctx, cancel_wait = context.WithTimeout(spc.route.Cts.S.ctx, 5 * time.Second) // TODO: make this configurable
wait_for_started:
for {
select {
@ -98,14 +98,14 @@ wait_for_started:
if errors.Is(err, io.EOF) || strings.Contains(err.Error(), "use of closed network connection") { // i don't like this way to check this error.
err = pss.Send(MakePeerEofPacket(spc.route.Id, spc.conn_id))
if err != nil {
spc.route.Cts.svr.log.Write(spc.route.Cts.sid, LOG_ERROR,
spc.route.Cts.S.log.Write(spc.route.Cts.sid, LOG_ERROR,
"Failed to send peer_eof event(%d,%d,%s,%s) to client - %s",
spc.route.Id, spc.conn_id, conn_raddr, conn_laddr, err.Error())
goto done
}
goto wait_for_stopped
} else {
spc.route.Cts.svr.log.Write(spc.route.Cts.sid, LOG_ERROR,
spc.route.Cts.S.log.Write(spc.route.Cts.sid, LOG_ERROR,
"Failed to read data from peer(%d,%d,%s,%s) - %s",
spc.route.Id, spc.conn_id, conn_raddr, conn_laddr, err.Error())
goto done
@ -114,7 +114,7 @@ wait_for_started:
err = pss.Send(MakePeerDataPacket(spc.route.Id, spc.conn_id, buf[:n]))
if err != nil {
spc.route.Cts.svr.log.Write(spc.route.Cts.sid, LOG_ERROR,
spc.route.Cts.S.log.Write(spc.route.Cts.sid, LOG_ERROR,
"Failed to send data from peer(%d,%d,%s,%s) to client - %s",
spc.route.Id, spc.conn_id, conn_raddr, conn_laddr, err.Error())
goto done
@ -134,7 +134,7 @@ wait_for_stopped:
done:
err = pss.Send(MakePeerStoppedPacket(spc.route.Id, spc.conn_id, spc.conn.RemoteAddr().String(), spc.conn.LocalAddr().String()))
if err != nil {
spc.route.Cts.svr.log.Write(spc.route.Cts.sid, LOG_ERROR,
spc.route.Cts.S.log.Write(spc.route.Cts.sid, LOG_ERROR,
"Failed to send peer_stopped(%d,%d,%s,%s) to client - %s",
spc.route.Id, spc.conn_id, conn_raddr, conn_laddr, err.Error())
// nothing much to do about the failure of sending this
@ -206,21 +206,21 @@ func (spc *ServerPeerConn) ReportEvent(event_type PACKET_KIND, event_data interf
var err error
_, err = spc.conn.Write(data)
if err != nil {
spc.route.Cts.svr.log.Write(spc.route.Cts.sid, LOG_ERROR,
spc.route.Cts.S.log.Write(spc.route.Cts.sid, LOG_ERROR,
"Failed to write data from %s to peer(%d,%d,%s) - %s",
spc.route.Cts.RemoteAddr, spc.route.Id, spc.conn_id, spc.conn.RemoteAddr().String(), err.Error())
spc.ReqStop()
}
} else {
// this must not happen.
spc.route.Cts.svr.log.Write(spc.route.Cts.sid, LOG_ERROR,
spc.route.Cts.S.log.Write(spc.route.Cts.sid, LOG_ERROR,
"Protocol error - invalid data in peer_data event from %s to peer(%d,%d,%s)",
spc.route.Cts.RemoteAddr, spc.route.Id, spc.conn_id, spc.conn.RemoteAddr().String())
spc.ReqStop()
}
} else {
// protocol error. the client must not relay more data from the client-side peer after EOF.
spc.route.Cts.svr.log.Write(spc.route.Cts.sid, LOG_ERROR,
spc.route.Cts.S.log.Write(spc.route.Cts.sid, LOG_ERROR,
"Protocol error - redundant data from %s to (%d,%d,%s)",
spc.route.Cts.RemoteAddr, spc.route.Id, spc.conn_id, spc.conn.RemoteAddr().String())
spc.ReqStop()