fix config.go file

This commit is contained in:
wiaamm 2025-05-27 16:55:51 +03:00
parent 3cf732b3f6
commit 5cf990310b
3 changed files with 84 additions and 90 deletions

View File

@ -239,45 +239,43 @@ func (p *parser) Merge(parent interface{}, child interface{}) interface{} {
return &newConfig return &newConfig
} }
func ConfigFactory(c interface{}) api.StreamFilterFactory { func ConfigFactory(c interface{}, callbacks api.FilterCallbackHandler) api.StreamFilter {
conf, ok := c.(*config) conf, ok := c.(*config)
if !ok { if !ok {
panic("unexpected config type") panic("unexpected config type")
} }
return func(callbacks api.FilterCallbackHandler) api.StreamFilter { worker_thread_id := int(C.get_thread_id())
worker_thread_id := int(C.get_thread_id()) api.LogDebugf("worker_thread_id: %d", worker_thread_id)
api.LogDebugf("worker_thread_id: %d", worker_thread_id) if _, ok := thread_to_attachment_mapping[int(worker_thread_id)]; !ok {
if _, ok := thread_to_attachment_mapping[int(worker_thread_id)]; !ok { api.LogDebugf("need to add new thread to the map")
api.LogDebugf("need to add new thread to the map") map_size := len(attachment_to_thread_mapping)
map_size := len(attachment_to_thread_mapping) if map_size < len(attachments_map) {
if map_size < len(attachments_map) { attachment_to_thread_mapping[map_size] = worker_thread_id
attachment_to_thread_mapping[map_size] = worker_thread_id thread_to_attachment_mapping[worker_thread_id] = map_size
thread_to_attachment_mapping[worker_thread_id] = map_size api.LogDebugf("len(attachment_to_thread_mapping): %d", len(attachment_to_thread_mapping))
api.LogDebugf("len(attachment_to_thread_mapping): %d", len(attachment_to_thread_mapping)) api.LogDebugf("thread_to_attachment_mapping: %v", thread_to_attachment_mapping)
api.LogDebugf("thread_to_attachment_mapping: %v", thread_to_attachment_mapping) api.LogDebugf("attachment_to_thread_mapping: %v", attachment_to_thread_mapping)
api.LogDebugf("attachment_to_thread_mapping: %v", attachment_to_thread_mapping) } else {
} else { panic("unexpected thread id")
panic("unexpected thread id")
}
} }
}
worker_id := thread_to_attachment_mapping[int(worker_thread_id)] worker_id := thread_to_attachment_mapping[int(worker_thread_id)]
api.LogDebugf("worker_id: %d", worker_id) api.LogDebugf("worker_id: %d", worker_id)
filter_id.Add(1) filter_id.Add(1)
session_id := filter_id.Load() session_id := filter_id.Load()
attachment_ptr := attachments_map[worker_id] attachment_ptr := attachments_map[worker_id]
session_data := C.InitSessionData((*C.NanoAttachment)(attachment_ptr), C.SessionID(session_id)) session_data := C.InitSessionData((*C.NanoAttachment)(attachment_ptr), C.SessionID(session_id))
return &filter{ return &filter{
callbacks: callbacks, callbacks: callbacks,
config: conf, config: conf,
session_id: session_id, session_id: session_id,
cp_attachment: attachment_ptr, cp_attachment: attachment_ptr,
session_data: session_data, session_data: session_data,
request_structs: attachment_to_filter_request_structs[worker_id], request_structs: attachment_to_filter_request_structs[worker_id],
}
} }
} }

View File

@ -239,45 +239,43 @@ func (p *parser) Merge(parent interface{}, child interface{}) interface{} {
return &newConfig return &newConfig
} }
func ConfigFactory(c interface{}) api.StreamFilterFactory { func ConfigFactory(c interface{}, callbacks api.FilterCallbackHandler) api.StreamFilter {
conf, ok := c.(*config) conf, ok := c.(*config)
if !ok { if !ok {
panic("unexpected config type") panic("unexpected config type")
} }
return func(callbacks api.FilterCallbackHandler) api.StreamFilter { worker_thread_id := int(C.get_thread_id())
worker_thread_id := int(C.get_thread_id()) api.LogDebugf("worker_thread_id: %d", worker_thread_id)
api.LogDebugf("worker_thread_id: %d", worker_thread_id) if _, ok := thread_to_attachment_mapping[int(worker_thread_id)]; !ok {
if _, ok := thread_to_attachment_mapping[int(worker_thread_id)]; !ok { api.LogDebugf("need to add new thread to the map")
api.LogDebugf("need to add new thread to the map") map_size := len(attachment_to_thread_mapping)
map_size := len(attachment_to_thread_mapping) if map_size < len(attachments_map) {
if map_size < len(attachments_map) { attachment_to_thread_mapping[map_size] = worker_thread_id
attachment_to_thread_mapping[map_size] = worker_thread_id thread_to_attachment_mapping[worker_thread_id] = map_size
thread_to_attachment_mapping[worker_thread_id] = map_size api.LogDebugf("len(attachment_to_thread_mapping): %d", len(attachment_to_thread_mapping))
api.LogDebugf("len(attachment_to_thread_mapping): %d", len(attachment_to_thread_mapping)) api.LogDebugf("thread_to_attachment_mapping: %v", thread_to_attachment_mapping)
api.LogDebugf("thread_to_attachment_mapping: %v", thread_to_attachment_mapping) api.LogDebugf("attachment_to_thread_mapping: %v", attachment_to_thread_mapping)
api.LogDebugf("attachment_to_thread_mapping: %v", attachment_to_thread_mapping) } else {
} else { panic("unexpected thread id")
panic("unexpected thread id")
}
} }
}
worker_id := thread_to_attachment_mapping[int(worker_thread_id)] worker_id := thread_to_attachment_mapping[int(worker_thread_id)]
api.LogDebugf("worker_id: %d", worker_id) api.LogDebugf("worker_id: %d", worker_id)
filter_id.Add(1) filter_id.Add(1)
session_id := filter_id.Load() session_id := filter_id.Load()
attachment_ptr := attachments_map[worker_id] attachment_ptr := attachments_map[worker_id]
session_data := C.InitSessionData((*C.NanoAttachment)(attachment_ptr), C.SessionID(session_id)) session_data := C.InitSessionData((*C.NanoAttachment)(attachment_ptr), C.SessionID(session_id))
return &filter{ return &filter{
callbacks: callbacks, callbacks: callbacks,
config: conf, config: conf,
session_id: session_id, session_id: session_id,
cp_attachment: attachment_ptr, cp_attachment: attachment_ptr,
session_data: session_data, session_data: session_data,
request_structs: attachment_to_filter_request_structs[worker_id], request_structs: attachment_to_filter_request_structs[worker_id],
}
} }
} }

View File

@ -239,45 +239,43 @@ func (p *parser) Merge(parent interface{}, child interface{}) interface{} {
return &newConfig return &newConfig
} }
func ConfigFactory(c interface{}) api.StreamFilterFactory { func ConfigFactory(c interface{}, callbacks api.FilterCallbackHandler) api.StreamFilter {
conf, ok := c.(*config) conf, ok := c.(*config)
if !ok { if !ok {
panic("unexpected config type") panic("unexpected config type")
} }
return func(callbacks api.FilterCallbackHandler) api.StreamFilter { worker_thread_id := int(C.get_thread_id())
worker_thread_id := int(C.get_thread_id()) api.LogDebugf("worker_thread_id: %d", worker_thread_id)
api.LogDebugf("worker_thread_id: %d", worker_thread_id) if _, ok := thread_to_attachment_mapping[int(worker_thread_id)]; !ok {
if _, ok := thread_to_attachment_mapping[int(worker_thread_id)]; !ok { api.LogDebugf("need to add new thread to the map")
api.LogDebugf("need to add new thread to the map") map_size := len(attachment_to_thread_mapping)
map_size := len(attachment_to_thread_mapping) if map_size < len(attachments_map) {
if map_size < len(attachments_map) { attachment_to_thread_mapping[map_size] = worker_thread_id
attachment_to_thread_mapping[map_size] = worker_thread_id thread_to_attachment_mapping[worker_thread_id] = map_size
thread_to_attachment_mapping[worker_thread_id] = map_size api.LogDebugf("len(attachment_to_thread_mapping): %d", len(attachment_to_thread_mapping))
api.LogDebugf("len(attachment_to_thread_mapping): %d", len(attachment_to_thread_mapping)) api.LogDebugf("thread_to_attachment_mapping: %v", thread_to_attachment_mapping)
api.LogDebugf("thread_to_attachment_mapping: %v", thread_to_attachment_mapping) api.LogDebugf("attachment_to_thread_mapping: %v", attachment_to_thread_mapping)
api.LogDebugf("attachment_to_thread_mapping: %v", attachment_to_thread_mapping) } else {
} else { panic("unexpected thread id")
panic("unexpected thread id")
}
} }
}
worker_id := thread_to_attachment_mapping[int(worker_thread_id)] worker_id := thread_to_attachment_mapping[int(worker_thread_id)]
api.LogDebugf("worker_id: %d", worker_id) api.LogDebugf("worker_id: %d", worker_id)
filter_id.Add(1) filter_id.Add(1)
session_id := filter_id.Load() session_id := filter_id.Load()
attachment_ptr := attachments_map[worker_id] attachment_ptr := attachments_map[worker_id]
session_data := C.InitSessionData((*C.NanoAttachment)(attachment_ptr), C.SessionID(session_id)) session_data := C.InitSessionData((*C.NanoAttachment)(attachment_ptr), C.SessionID(session_id))
return &filter{ return &filter{
callbacks: callbacks, callbacks: callbacks,
config: conf, config: conf,
session_id: session_id, session_id: session_id,
cp_attachment: attachment_ptr, cp_attachment: attachment_ptr,
session_data: session_data, session_data: session_data,
request_structs: attachment_to_filter_request_structs[worker_id], request_structs: attachment_to_filter_request_structs[worker_id],
}
} }
} }