Skip to content

Golang library to handle transparent remote node pairing

License

Notifications You must be signed in to change notification settings

kairos-io/go-nodepair

Folders and files

NameName
Last commit message
Last commit date

Latest commit

7c55179 · Feb 5, 2025

History

76 Commits
Aug 23, 2024
Apr 20, 2023
Jul 11, 2024
Apr 23, 2024
Apr 20, 2023
Feb 5, 2025
Dec 5, 2024
Jul 12, 2024
Oct 6, 2023
Feb 1, 2022
Jul 11, 2024
Oct 4, 2023

Repository files navigation

go-nodepair

A small library to handle transparent remote node pairing.

Usage

On one side (that is a separate binary, or either a go routine), we generate a token, display it as QR code and we wait for pairing to complete:

import (
	"context"
	"fmt"
	"time"

	nodepair "github.com/kairos-io/go-nodepair"
	qr "github.com/kairos-io/go-nodepair/qrcode"
)

func main() {

	ctx, cancel := context.WithCancel(context.Background())

    // Generate a token, and print it out on screen as QR code
	t := nodepair.GenerateToken()
	qr.Print(t)

	// bind to the token that we previously generated until we paired with the other remote
    r := map[string]string{}
	nodepair.Receive(ctx, &r, nodepair.WithToken(t))
	fmt.Println("Just got", r)

}

Pairing is a syncronous step that waits for the other party to touch base. When pairing completes on both ends, the normal execution flow restarts.

The other party can send a payload which can be any type (interface{}).

On the other end:

import (
	"context"
	"fmt"
	"time"

	nodepair "github.com/kairos-io/go-nodepair"
	qr "github.com/kairos-io/go-nodepair/qrcode"
)

func main() {
	ctx, cancel := context.WithCancel(context.Background())

	if err := nodepair.Send(
		ctx, map[string]string{"foo": "Bar"},
		nodepair.WithReader(qr.Reader),
	); err != nil {
		fmt.Println("ERROR", err)
		cancel()
	}
	fmt.Println("Finished sending pairing payload")
}

The pairing options can be used in both sender/receiver, allowing to use QR code also for receiving payload, and vice-versa.

About

Golang library to handle transparent remote node pairing

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages