feat(notify): 重构通信内核并补齐 stream/bulk/record/transfer 能力
- 引入 LogicalConn/TransportConn 分层,ClientConn 保留兼容适配层 - 新增 Stream、Bulk、RecordStream 三条数据面能力及对应控制路径 - 完成 transfer/file 传输内核与状态快照、诊断能力 - 补齐 reconnect、inbound dispatcher、modern psk 等基础模块 - 增加大规模回归、并发与基准测试覆盖 - 更新依赖库
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
package notify
|
||||
|
||||
import "context"
|
||||
|
||||
func (c *ClientCommon) SetRecordStreamHandler(fn func(RecordAcceptInfo) error) {
|
||||
runtime := c.getRecordRuntime()
|
||||
if runtime == nil {
|
||||
return
|
||||
}
|
||||
runtime.setHandler(fn)
|
||||
}
|
||||
|
||||
func (c *ClientCommon) OpenRecordStream(ctx context.Context, opt RecordOpenOptions) (RecordStream, error) {
|
||||
if c == nil {
|
||||
return nil, errStreamClientNil
|
||||
}
|
||||
opt = normalizeRecordOpenOptions(opt)
|
||||
stream, err := c.OpenStream(ctx, opt.Stream)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
record, err := WrapStreamAsRecord(stream, opt)
|
||||
if err != nil {
|
||||
_ = stream.Reset(err)
|
||||
return nil, err
|
||||
}
|
||||
return record, nil
|
||||
}
|
||||
|
||||
func (c *ClientCommon) claimInboundRecordStream(stream *streamHandle) (bool, error) {
|
||||
if stream == nil || stream.Channel() != StreamRecordChannel {
|
||||
return false, nil
|
||||
}
|
||||
runtime := c.getRecordRuntime()
|
||||
if runtime == nil {
|
||||
return true, errRecordRuntimeNil
|
||||
}
|
||||
handler := runtime.handlerSnapshot()
|
||||
if handler == nil {
|
||||
return true, errRecordHandlerNotConfigured
|
||||
}
|
||||
record, err := WrapStreamAsRecord(stream, RecordOpenOptions{
|
||||
Stream: StreamOpenOptions{
|
||||
ID: stream.ID(),
|
||||
Channel: stream.Channel(),
|
||||
Metadata: stream.Metadata(),
|
||||
ReadTimeout: stream.readTimeoutSnapshot(),
|
||||
WriteTimeout: stream.writeTimeoutSnapshot(),
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return true, err
|
||||
}
|
||||
info := RecordAcceptInfo{
|
||||
ID: stream.ID(),
|
||||
Metadata: stream.Metadata(),
|
||||
TransportGeneration: stream.TransportGeneration(),
|
||||
RecordStream: record,
|
||||
}
|
||||
go func() {
|
||||
if err := handler(info); err != nil {
|
||||
_ = record.Reset(err)
|
||||
}
|
||||
}()
|
||||
return true, nil
|
||||
}
|
||||
Reference in New Issue
Block a user