The Fortune of War by Patrick O'Brian
Captain Jack Aubrey, R. N., arrives in the Dutch East Indies to find himself appointed to the command of the fastest and best-armed frigate in the Navy. He and his friend Stephen Maturin take passage for England in a dispatch vessel. But the War of 1812 breaks out while they are en route. Bloody actions precipitate them both into new and unexpected scenes where Stephen's past activities as a secret agent return on him with a vengeance.