|
26 | 26 | import org.metricshub.ipmi.core.coding.commands.IpmiVersion; |
27 | 27 | import org.metricshub.ipmi.core.coding.commands.PrivilegeLevel; |
28 | 28 | import org.metricshub.ipmi.core.coding.commands.ResponseData; |
| 29 | +import org.metricshub.ipmi.core.coding.commands.session.GetChannelAuthenticationCapabilities; |
29 | 30 | import org.metricshub.ipmi.core.coding.commands.session.GetChannelAuthenticationCapabilitiesResponseData; |
30 | 31 | import org.metricshub.ipmi.core.coding.commands.session.GetChannelCipherSuitesResponseData; |
31 | 32 | import org.metricshub.ipmi.core.coding.commands.session.OpenSessionResponseData; |
|
61 | 62 | import org.metricshub.ipmi.core.sm.states.Authcap; |
62 | 63 | import org.metricshub.ipmi.core.sm.states.Ciphers; |
63 | 64 | import org.metricshub.ipmi.core.sm.states.SessionValid; |
| 65 | +import org.metricshub.ipmi.core.sm.states.State; |
64 | 66 | import org.metricshub.ipmi.core.sm.states.Uninitialized; |
65 | 67 | import org.metricshub.ipmi.core.transport.Messenger; |
66 | 68 |
|
@@ -666,31 +668,35 @@ public void notify(StateMachineAction action) { |
666 | 668 | } |
667 | 669 |
|
668 | 670 | /** |
669 | | - * {@link TimerTask} runner - periodically sends no-op messages to keep the |
670 | | - * session up |
| 671 | + * The keep-alive request: queued like any request, so that its tag stays reserved until its reply arrives or it |
| 672 | + * times out, but owned by nobody: its reply is discarded and its timeout is not reported to the listeners. |
| 673 | + */ |
| 674 | + public static final class KeepAlive extends GetChannelAuthenticationCapabilities { |
| 675 | + /** |
| 676 | + * Creates the keep-alive request of a session. |
| 677 | + * |
| 678 | + * @param cipherSuite the {@link CipherSuite} of the session |
| 679 | + */ |
| 680 | + public KeepAlive(CipherSuite cipherSuite) { |
| 681 | + super(IpmiVersion.V20, IpmiVersion.V20, cipherSuite, PrivilegeLevel.Callback, TypeConverter.intToByte(0xe)); |
| 682 | + } |
| 683 | + } |
| 684 | + |
| 685 | + /** |
| 686 | + * {@link TimerTask} runner - periodically sends a no-op message to keep the session up. The message is a |
| 687 | + * {@link KeepAlive}: its reply is discarded, while a reply to the same command sent by the application is |
| 688 | + * delivered to the application. When the message queue is full, the keep-alive of this period is skipped. |
671 | 689 | */ |
672 | 690 | @Override |
673 | 691 | public void run() { |
674 | | - int result = -1; |
675 | | - while (!Thread.currentThread().isInterrupted() |
676 | | - && result <= 0 |
677 | | - && stateMachine.getCurrent() instanceof SessionValid) { |
678 | | - try { |
679 | | - |
680 | | - result = sendMessage( |
681 | | - new org.metricshub.ipmi.core.coding.commands.session.GetChannelAuthenticationCapabilities( |
682 | | - IpmiVersion.V20, |
683 | | - IpmiVersion.V20, |
684 | | - ((SessionValid) stateMachine.getCurrent()).getCipherSuite(), |
685 | | - PrivilegeLevel.Callback, |
686 | | - TypeConverter.intToByte(0xe)), |
687 | | - false); |
688 | | - |
689 | | - Thread.sleep(1000); |
690 | | - |
691 | | - } catch (Exception e) { |
692 | | - LOGGER.error(e.getMessage(), e); |
693 | | - } |
| 692 | + State current = stateMachine.getCurrent(); |
| 693 | + if (!stateMachine.isActive() || !(current instanceof SessionValid)) { |
| 694 | + return; |
| 695 | + } |
| 696 | + try { |
| 697 | + sendMessage(new KeepAlive(((SessionValid) current).getCipherSuite()), false); |
| 698 | + } catch (Exception e) { |
| 699 | + LOGGER.error("Keep-alive failed: " + e.getMessage(), e); |
694 | 700 | } |
695 | 701 | } |
696 | 702 |
|
|
0 commit comments