The router->last_written is used to store the position where the last event was written. The replication header is also stored in a separate structure in the router which is used later when the last packet of a multi-packet event arrives.