Use of globals to store ephemeral / in-transit data
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 25/100
- Issue type
- Refactor
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- c
- Domain
- backend-api-design, embedded-iot
Research direction
Start in fsw/src/cf_cfdp_r.c at CF_CFDP_R_ProcessFd and the caller around lines 436-447, then trace how packet data moves through the CFDP processing APIs. Done means the packet data access strategy is consistent throughout these calls and ephemeral state is not implicitly mixed with passed pointers; no tests or additional files are identified in the issue.
Written by the indexing model from the issue text.
Description
CF stores its current working pointers in a global variable called CF_AppData.engine:
In particular:
CF_AppData.engine.in.msg has a pointer to the buffer last received from SB
CF_AppData.engine.in.bytes_received has the size of that buffer (and is actually updated during the course of processing)
CF_AppData.engine.in.src and CF_AppData.engine.in.dst have the data extracted from the header of the most recent message.
and so forth...
Importantly: none of these values are supposed to be carried across wakeups. All values are reset in their entirety on every wakeup, and in fact with each channel. All data is ephemeral and is only valid while the CFDP app is actively processing that packet. As soon as processing of the current packet completes, the data is no longer valid. When the wakeup cycle completes, only the CF_AppData.engine.in.msg is actively cleared. All other fields will be left with whatever data was in them.
Also notable - there is a mixture of API calls where sometimes the pointer to the packet data is passed in directly, as it is here via the ph argument:
The call to CF_CFDP_R_ProcessFd also needs the packet data, but it does not pass it along. Instead, this function grabs it from the global (theoretically the same packet):
This inconsistency should be addressed. If the intent is to always store the current packet in a global, then code needing to access it should always retrieve it from the global. There should not be some APIs which pass a pointer to the structure, mixed with others that get it directly from the global (where they are supposed to be acting on the same data), as this creates the opportunity that they could diverge.
For ephemeral data, it is fine to pre-allocate a buffer in a global to avoid dynamic allocation, but the pointer to this data should be passed consistently down through the API where needed. This design allows for safer evolution, permitting the use of multiple buffers or even multiple threads should that become a requirement (e.g. create a child task per CFDP channel to make them more independent).
- Dominant language
- C
- Stars
- 123
- Forks
- 82
- Avg merge
- 2d 22h
- Merged PRs (30d)
- 2
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from nasa/CF
-
CF_CFDP_S_SendFileData computes the file checksum from the SB buffer after CFE_SB_TransmitBufferOpen
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Assert checks non-existent variable (`pt`) in `CF_CFDP_ProcessPlaybackDirectory()`May be free again A pull request for this issue was closed without being merged. Openinvalid
Difficulty 1/5 Under an hour Newbie friendliness 68/100
Similar issues
-
needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
389ds/389-ds-base#8251 ·
Maintainers usually reply within 1 day
-
bug data-types
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
ClickHouse/clickhouse-cpp#645 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
ROCm/hrx-system#3628 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
OpenPrinting/cups#1844 ·
Maintainers usually reply within 1 day