Skip to content

Commit 4b0b56d

Browse files
mfillstipakov
authored andcommitted
GUI: Add key direction toggle
I found it very unintuitive that I have to click the MP radio button to switch the key direction in P2P mode. Therefore, I added a key-dir option next to the New Key button.
1 parent 4eda816 commit 4b0b56d

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

gui/gui.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ HWND hMPListenAddress, hMPListenPort,
2525
hP2PRemoteAddress, hP2PRemotePort,
2626
hCCMessage, hCCRemoteAddress, hCCRemotePort,
2727
hMPNewPeerLocalIP, hMPNewPeerLocalPort, hMPNewPeerRemoteIP, hMPNewPeerRemotePort, hMPNewPeerVPNIP, hMPNewPeerPeerId,
28-
hNewKeyPeerId, hNewKeyKeySlot, hNewKeyKeyId,
28+
hNewKeyPeerId, hNewKeyKeySlot, hNewKeyKeyId, hNewKeyKeyDir,
2929
hSetPeerPeerId, hSetPeerInterval, hSetPeerTimeout, hSetPeerMSS,
3030
hDelPeerPeerId,
3131
hSwapKeysPeerId,
@@ -460,9 +460,8 @@ NewKey()
460460
OVPN_CRYPTO_DATA crypto_data = {};
461461
constexpr int keyLen = sizeof(crypto_data.Encrypt.Key);
462462

463-
bool mp = SendMessage(hModes[1], BM_GETCHECK, 0, 0) == BST_CHECKED;
464-
bool keyDir = mp ? 1 : 0;
465-
if (keyDir) {
463+
auto keyDir = SendMessageW(hNewKeyKeyDir, LB_GETCURSEL, 0, 0);
464+
if (keyDir == 1) {
466465
CopyMemory(crypto_data.Encrypt.Key, buf.data() + keyLen, keyLen);
467466
CopyMemory(crypto_data.Decrypt.Key, buf.data(), keyLen);
468467
}
@@ -489,7 +488,7 @@ NewKey()
489488
Log("DeviceIoControl(OVPN_IOCTL_NEW_KEY) failed with code ", GetLastError());
490489
}
491490
else {
492-
Log("New key added, peer-id: ", peerId, ", slot: ", (keySlot == 0) ? "primary" : "secondary", ", key-id: ", keyId);
491+
Log("New key added, peer-id: ", peerId, ", slot: ", (keySlot == 0) ? "primary" : "secondary", ", key-id: ", keyId, ", key-dir: ", (keyDir == 1) ? "Reversed" : "Normal");
493492
}
494493
}
495494

@@ -751,6 +750,8 @@ LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
751750
hNewKeyKeySlot = CreateListBox(hwnd, 300, 250, 100, {L"Primary", L"Secondary"});
752751
CreateTextLabel(hwnd, L"key-id", 420, 260, 60);
753752
hNewKeyKeyId = CreateEditBox(hwnd, L"0", 480, 260, 60);
753+
CreateTextLabel(hwnd, L"key-dir", 560, 260, 60);
754+
hNewKeyKeyDir = CreateListBox(hwnd, 620, 250, 100, { L"Normal", L"Reversed" });
754755

755756
CreatePushButton(hwnd, OVPN_IOCTL_SET_PEER, 10, 310);
756757
hSetPeerPeerId = CreateEditBox(hwnd, L"1", 150, 310, 60);

0 commit comments

Comments
 (0)