## 4 Proposed Architecture and Implementation
### Communication Proof of Concept  
In our implementation, we developed and deployed two primary communication scenarios within the blockchain-based secure vehicle communication system: vehicle-to-vehicle (V2V) and vehicle-to-infrastructure (V2I) communication. * Secure vehicle-to-vehicle communication (V2V)
* Data broadcast-vehicles broadcast signed messages, such as emergency braking or hazard warnings, to nearby vehicles and RSUs. * Message verification (Algorithm 1)-the receiving vehicles verify the authenticity of the message by checking the sender's public key and the blockchain entries. This ensures that the message does not originate from a malicious actor (protection against Sybil attacks). ```
1:Input: Message \(m\), Sender's Public Key \(K_{pub}\)
2:Output: Validation Status (\(\textbf{True}/\textbf{False}\))
3:Step 1: Extract the digital signature from \(m\)
4:Step 2: Verify the signature using \(K_{pub}\)
5:Step 3: Check the blockchain ledger for the sender's identity
6:if signature and sender identity are valid then
7:return True
8:else
9:return False
10:endif
```  
**Algorithm 1** Message verification algorithm  
Data sharing-after validation, the data are used to support the receiving vehicle's decision making (e.g., adjusting speed to avoid a collision). * Secure vehicle-to-infrastructure communication (V2I)
* Data aggregation with RSUs-RSUs collect and process data from nearby vehicles. They can take over local traffic management, store road condition data, or interact with traffic lights to optimize traffic flow. * Blockchain recording-important V2I interactions (such as toll payments or the prioritization of emergency vehicles) are recorded in the blockchain for transparency and verification. The message does not originate from a malicious actor (protection against Sybil attacks). * Fog computing-part of the data processing takes place at the edge (RSUs) so that decisions can be made in real time without having to send all data to the cloud, reducing latency. In our implementation, we take into account the dynamic nature of vehicles moving across different geographical areas and ensure that each vehicle remains connected to the nearest available roadside unit (RSU). As vehicles are constantly changing position, it is crucial to maintain an efficient and secure communication link with the nearest RSU for reliable data exchange. To achieve this, we have developed an algorithm that calculates the distance between the moving vehicle and the nearby RSUs and determines which RSUs are within communication range. This algorithm ensures that the vehicle seamlessly connects to the RSU that offers the best signal strength and proximity, enabling continuous and secure vehicle-to-infrastructure (V2I) communication. Algorithm 2 uses the current GPS position of the vehicle and calculates the distance to each RSU using [PERSON]'s formula [23], which is well suited to calculating distances on the earth's surface. If the calculated distance is less than or equal to the RSU's communication range, the RSU is considered \"in range\" and is added to the list of available RSUs for the vehicle. This allows the vehicle to dynamically adjust its connection as it moves through different regions.