Skip to content

Refactoring go code for bitmask-core integration #758

Pea Nut requested to merge v5-client-refactoring into main

Most part of this MR is just a code refactoring. With the changes, we now have a switch we can (later) use to implement api version 5 support in a nice way:

func initBitmaskVPN() (b Bitmask, err error) {
    log.Printf("Using api version %d\n", config.ApiVersion)
    if config.ApiVersion == 3 { 
        b, err = legacy.Init()
        if err != nil {
            log.Printf("An error ocurred starting bitmask vpn: %v", err)
        }   
    } else if config.ApiVersion == 5 { 
        panic("This needs to be implemented")
    } else {
        panic(fmt.Sprintf("ApiVersion in config file must be 3 or 5. Given: %d\n", config.ApiVersion))
    }   
    return b, err 
}

I moved a lot of things. The reason was to get most of the stuff away from the bitmask code (vpn package). Then we can call it later for the if we implement v5. The current v3 implementation was moved to pkg/bitmask/legacy/. Before the change, there was an interface called Bitmask and an actual struct also called Bitmask that implemented the interface. Now the old Bitmask struct is called Bitmask3. I made it a bit more explicit in the code. Bitmask v5 will also be an implementation of the interface.

Bitmask3 is now in a package legacy. If we now check the code left to Bitmask3 most functions are the exported ones. We can now copy the Bitmask3 stuff and adjust it for the Bitmask5 implementation.

Currently, the api version is hardcoded in the provider settings. I fixed the build stuff so that you can just run make vendor and make build. Please check the commit messages, I think they make things more clear.

Just write me on Matrix if you want to discuss @jkito @cyberta

Merge request reports