Skip to content

Commit

Permalink
fix(ios): change the way the advertise id is retrieved
Browse files Browse the repository at this point in the history
Signed-off-by: Sacha Froment <sfroment42@gmail.com>
  • Loading branch information
sfroment committed Oct 19, 2018
1 parent d3f0546 commit b8255df
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 40 deletions.
25 changes: 13 additions & 12 deletions core/cmd/berty/daemon.go
Expand Up @@ -70,15 +70,7 @@ type daemonOptions struct {
mdns bool `mapstructure:"mdns"`
}

var id uuid.UUID

func daemonSetupFlags(flags *pflag.FlagSet, opts *daemonOptions) {
var err error
id, err = uuid.NewV4()
if err != nil {
panic(err)
}

flags.BoolVar(&opts.dropDatabase, "drop-database", false, "drop database to force a reinitialization")
flags.BoolVar(&opts.hideBanner, "hide-banner", false, "hide banner")
flags.BoolVar(&opts.initOnly, "init-only", false, "stop after node initialization (useful for integration tests")
Expand All @@ -89,7 +81,7 @@ func daemonSetupFlags(flags *pflag.FlagSet, opts *daemonOptions) {
flags.StringVar(&opts.gqlBind, "gql-bind", ":8700", "Bind graphql api")
flags.StringVarP(&opts.identity, "p2p-identity", "i", "", "set p2p identity")
flags.StringSliceVar(&opts.bootstrap, "bootstrap", defaultBootstrap, "boostrap peers")
flags.StringSliceVar(&opts.bindP2P, "bind-p2p", []string{"/ip4/0.0.0.0/tcp/0", fmt.Sprintf("/ble/%s", id.String())}, "p2p listening address")
flags.StringSliceVar(&opts.bindP2P, "bind-p2p", []string{"/ip4/0.0.0.0/tcp/0", "/ble/00000000-0000-0000-0000-000000000000"}, "p2p listening address")
_ = viper.BindPFlags(flags)
}

Expand Down Expand Up @@ -258,12 +250,21 @@ func daemon(opts *daemonOptions) error {

for _, v := range opts.bindP2P {
if strings.HasPrefix(v, "/ble/") {
// bleUUID := strings.TrimPrefix(v, "/ble/")
sourceMultiAddr, err := ma.NewMultiaddr(v)
var conf entity.Config
err = db.First(&conf).Error
if err != nil {
id, err := uuid.NewV4()
if err != nil {
return err
}
conf.ID = id.String()
}
opts.bindP2P[i] = fmt.Sprintf("/ble/%s", conf.ID)
sourceMultiAddr, err := ma.NewMultiaddr(opts.bindP2P[i])
if err != nil {
return err
}
bleTPT := ble.NewBLETransport(id.String(), sourceMultiAddr)
bleTPT := ble.NewBLETransport(conf.ID, sourceMultiAddr)
p2pOpts = append(p2pOpts, p2p.WithTransport(bleTPT))
}
}
Expand Down
30 changes: 2 additions & 28 deletions core/network/p2p/p2p.go
Expand Up @@ -114,11 +114,11 @@ func newDriver(ctx context.Context, cfg driverConfig) (*Driver, error) {
}

if cfg.enableMDNS {
// sa, err := mdns.NewMdnsService(ctx, host, time.Second, "berty")
sa, err := mdns.NewMdnsService(ctx, host, time.Second, "berty")
if err != nil {
logger().Warn("Failed to enable MDNS", zap.Error(err))
} else {
// sa.RegisterNotifee((*DriverDiscoveryNotifee)(driver))
sa.RegisterNotifee((*DriverDiscoveryNotifee)(driver))
}
}

Expand Down Expand Up @@ -280,7 +280,6 @@ func (d *Driver) BootstrapPeer(ctx context.Context, bootstrapAddr string) error
// given peer.ID.
func (d *Driver) Connect(ctx context.Context, pi pstore.PeerInfo) error {
// first, check if we're already connected.
fmt.Printf("LALALALALLLLLLLLAAAAAAAAAA\n\n\n\n\n\n")
if d.host.Network().Connectedness(pi.ID) == inet.Connected {
return nil
}
Expand All @@ -294,9 +293,7 @@ func (d *Driver) Connect(ctx context.Context, pi pstore.PeerInfo) error {
if len(addrs) < 1 {
// no addrs? find some with the routing system.
var err error
fmt.Printf("LALALALA\n")
pi, err = d.dht.FindPeer(ctx, pi.ID)
fmt.Printf("LALALALA %+v\n", pi)
if err != nil {
return err
}
Expand Down Expand Up @@ -331,29 +328,6 @@ func (d *Driver) Emit(ctx context.Context, e *p2p.Envelope) error {
}

func (d *Driver) EmitTo(ctx context.Context, channel string, e *p2p.Envelope) error {
fmt.Printf("ici %s\n", channel)
ntk := d.host.Network().(*swarm.Swarm)
fmt.Printf("new net %+v\n", ntk)
fmt.Printf("addrs %+v\n", d.host.Addrs())
// block, _ := pem.Decode([]byte(channel))
// if block == nil {
// panic("failed to parse PEM block containing the public key")
// }

// pub, err := x509.ParsePKIXPublicKey(block.Bytes)
// if err != nil {
// panic("failed to parse DER encoded public key: " + err.Error())
// }
// pk1, err := crypto.UnmarshalECDSAPublicKey([]byte(channel))
// fmt.Printf("pk1 %+v %+v\n", pk1, err)
pk2, err := crypto.UnmarshalEd25519PublicKey([]byte(channel))
fmt.Printf("pk2 %+v %+v\n", pk2, err)
pk3, err := crypto.UnmarshalRsaPublicKey([]byte(channel))
fmt.Printf("pk3 %+v %+v\n", pk3, err)
cid, _ := d.createCid(channel)
fmt.Printf("CID %+v\n", cid)
// fmt.Printf("transport %+v %+v\n", pk, err)
// pID, err := peer.IDB58Decode(channel)
ss, err := d.FindSubscribers(ctx, channel)
if err != nil {
return err
Expand Down

0 comments on commit b8255df

Please sign in to comment.