(ctx context.Context)
| 89 | } |
| 90 | |
| 91 | func (c *client) receiveID(ctx context.Context) (errc chan error) { |
| 92 | errc = make(chan error) |
| 93 | go func() { |
| 94 | defer close(errc) |
| 95 | |
| 96 | buffer, err := readFrom(c.conn) |
| 97 | if err != nil { |
| 98 | utils.ReportError(ctx, errc, errors.Errorf("readFrom %s : %w", c.conn.RemoteAddr().String(), err)) |
| 99 | return |
| 100 | } |
| 101 | |
| 102 | _, ptr, err := decodeBytes(buffer, nil) |
| 103 | if err != nil { |
| 104 | utils.ReportError(ctx, errc, errors.Errorf("decodeBytes: %w", err)) |
| 105 | return |
| 106 | } |
| 107 | |
| 108 | id, ok := ptr.Message.(*ID) |
| 109 | if !ok { |
| 110 | err = errors.Errorf("ID casting: %w", ErrCasting) |
| 111 | utils.ReportError(ctx, errc, err) |
| 112 | return |
| 113 | } |
| 114 | //ID should not be nil or the same with local ID |
| 115 | c.remoteID = id.GetId() |
| 116 | if string(c.remoteID) == string(c.localID) { |
| 117 | err = errors.Errorf("remoteID %b != localID %b: %w", |
| 118 | c.remoteID, c.localID, ErrDuplicateID) |
| 119 | utils.ReportError(ctx, errc, errors.Errorf("client : %w", err)) |
| 120 | } |
| 121 | if c.remoteID == nil { |
| 122 | err = errors.Errorf("remoteID is nil: %w", ErrNoRemoteID) |
| 123 | } |
| 124 | |
| 125 | //TODO: Move to other module |
| 126 | pub := c.suite.G2().Point() |
| 127 | if err = pub.UnmarshalBinary(id.GetPublicKey()); err != nil { |
| 128 | utils.ReportError(ctx, errc, errors.Errorf("UnmarshalBinary: %w", err)) |
| 129 | return |
| 130 | } |
| 131 | c.remotePubKey = pub |
| 132 | |
| 133 | var dhBytes []byte |
| 134 | dhKey := c.suite.Point().Mul(c.localSecKey, c.remotePubKey) |
| 135 | if dhBytes, err = dhKey.MarshalBinary(); err != nil { |
| 136 | utils.ReportError(ctx, errc, errors.Errorf("MarshalBinary: %w", err)) |
| 137 | return |
| 138 | } |
| 139 | c.dhKey = dhBytes[0:32] |
| 140 | c.dhNonce = dhBytes[32:44] |
| 141 | |
| 142 | return |
| 143 | }() |
| 144 | return |
| 145 | } |
| 146 | |
| 147 | func (c *client) sendID(ctx context.Context) (errc chan error) { |
| 148 | errc = make(chan error) |
no test coverage detected