Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
peterdettman committed Mar 11, 2019
1 parent f131471 commit f98bb79
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
25 changes: 1 addition & 24 deletions tls/src/main/java/org/bouncycastle/tls/DTLSRecordLayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ record = new byte[receiveLimit];
}

currentTimeMillis = System.currentTimeMillis();
waitMillis = getWaitMillis(timeout, currentTimeMillis);
waitMillis = Timeout.getWaitMillis(timeout, currentTimeMillis);
}

return -1;
Expand Down Expand Up @@ -671,27 +671,4 @@ private static long getMacSequenceNumber(int epoch, long sequence_number)
{
return ((epoch & 0xFFFFFFFFL) << 48) | sequence_number;
}

// private static int getWaitMillis(Timeout t)
// {
// return getWaitMillis(t, System.currentTimeMillis());
// }

private static int getWaitMillis(Timeout timeout, long currentTimeMillis)
{
if (null == timeout)
{
return 0;
}
long remainingMillis = timeout.remainingMillis(currentTimeMillis);
if (remainingMillis < 1L)
{
return -1;
}
if (remainingMillis > Integer.MAX_VALUE)
{
return Integer.MAX_VALUE;
}
return (int)remainingMillis;
}
}
23 changes: 23 additions & 0 deletions tls/src/main/java/org/bouncycastle/tls/Timeout.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,27 @@ synchronized long remainingMillis(long currentTimeMillis)

return remaining;
}

static int getWaitMillis(Timeout timeout)
{
return getWaitMillis(timeout, System.currentTimeMillis());
}

static int getWaitMillis(Timeout timeout, long currentTimeMillis)
{
if (null == timeout)
{
return 0;
}
long remainingMillis = timeout.remainingMillis(currentTimeMillis);
if (remainingMillis < 1L)
{
return -1;
}
if (remainingMillis > Integer.MAX_VALUE)
{
return Integer.MAX_VALUE;
}
return (int)remainingMillis;
}
}

0 comments on commit f98bb79

Please sign in to comment.