Beispiel #1
0
func NewLocalNode(cfg *Config) (*LocalNode, error) {
	var err error
	n := new(LocalNode)
	n.logger = log.L("local")

	n.secret, err = secure.NetworkSecretUnmarshal(cfg.SecretKey)
	if err != nil {
		return nil, err
	}

	n.config = cfg
	n.config.NetworkID = n.secret.InfoHash()
	n.state = NewState(n.secret)

	n.services = make(map[string]Service)

	n.AddService(&NetTable{})
	n.AddService(&ListenerService{})
	n.AddService(&DiscoveryDHT{})
	n.AddService(&InterfaceService{})
	//n.AddService(&STUNService{})
	n.AddService(&UPnPService{})
	n.AddService(&HttpService{})
	return n, nil
}
Beispiel #2
0
func actionGetIP(ctx *cli.Context) {
	if NetworkKey == "" {
		log.Fatal(keyNotSetError.Error())
	}

	secret, err := secure.NetworkSecretUnmarshal(NetworkKey)
	if err != nil {
		log.Fatal("error on decode network key, %v", err)
	}

	state := common.NewState(secret)
	state.Save()

	fmt.Println(state.PrivateIP.String())
	log.Info("private IP %q restored successfully", state.PrivateIP.String())
}
Beispiel #3
0
func actionNew(ctx *cli.Context) {
	var secret *secure.NetworkSecret
	var err error

	if len(ctx.Args()) > 0 {
		keyStr := ctx.Args().First()
		secret, err = secure.NetworkSecretUnmarshal(keyStr)
		if err != nil {
			log.Fatal("error on decode network key, %v", err)
		}
	} else {
		_, ipNet, err := net.ParseCIDR(ctx.String("CIDR"))
		if err != nil {
			log.Fatal("cidr parse error, %v", err)
		}
		secret = secure.NewNetworkSecret(ipNet)
	}
	fmt.Println(secret.Marshal())
}