utils/alignemnt: change function signiture from time.Duration to int for connection measurement functions

Issue #28 resolved
Alex Arends created an issue

During the development of the alignment system, the first approach was to ping a server and measure the latency as an indication of signal strength. The pinger used returned a time.Duration which was then integrated into the code structure. However as the situation changed, more methods of measuring signal strength were tested due to unsurprising results.

Since the code structure hinged on the use of a time.Duration, functions which would even return a non time related measurements were jerry rigged to return an integer as the same number but as a time duration. Ie; connectionStrength measures signal strength is dB, however it is returned as time.Duration(dB) in order to fit the signiture of the contexts it is used in.

functions effected are only used in this context:

aligner.go: line 132: return newBase(c, s, l, connectionStrength)

where the 4th argument is a ‘pinger’ function with the following sig:
ping func(input string) (time.Duration, error)

The pinger functions are the following:

calibrate.go: connectionStrength(hostname string) (time.Duration, error)
calibrate.go: uploadSpeed(s string) (time.Duration, error)
calibrate.go: packetLoss(addr string) (time.Duration, error)
calibrate.go: avePing(addr string) (time.Duration, error)

Of the 4 above functions, only avePing and uploadSpeed actually return a real time.Duration, the other two return some integer value which is the parsed into becoming a time.Duration at the moment before the function returns.

This code should be refactored such that all the functions just return an integer value. For the functions which return time, perhaps just return the result in milliseconds, however it shouldn’t really matter as result relativity is more important than the absolute value of each point.

In essence, the code must be refactored such that:
ping func(input string) (time.Duration, error)ping func(input string) (int, error)

for all relevant functions .

Comments (3)

  1. kortschak

    I started to have a look at this, but avePing and packetLoss are deadcode, so revising the signatures is not testable with the current codebase. I found something else to fix.

  2. Alex Arends reporter

    Going to work on this now, have started using lint ci and I’m ripping out any old code we don’t need, I’ll tie up some of the dead code loose ends in the process. I’m going to go through all of cmd and make sure that it is up to standard.

  3. Log in to comment